Compound data type: Difference between revisions
Content added Content deleted
(+ Pascal) |
m (→{{header|C++}}: pretty-printing of code) |
||
Line 56: | Line 56: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
<cpp> |
|||
struct Point |
|||
{ |
|||
int x; |
|||
int y; |
|||
}; |
|||
</cpp> |
|||
It is also possible to add a constructor (this allows the use of <tt>Point(x, y)</tt> in expressions): |
It is also possible to add a constructor (this allows the use of <tt>Point(x, y)</tt> in expressions): |
||
<cpp> |
|||
struct Point |
|||
{ |
|||
int x; |
|||
int y; |
|||
Point(int ax, int ay): x(ax), y(ax) {} |
|||
}; |
|||
</cpp> |
|||
Point can also be parametrized on the coordinate type: |
Point can also be parametrized on the coordinate type: |
||
<cpp> |
|||
⚫ | |||
{ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</cpp> |
|||
Of course, a constructor can be added in this case as well. |
Of course, a constructor can be added in this case as well. |
||