Compound data type: Difference between revisions
m
→{{header|C++}}: pretty-printing of code
(+ Pascal) |
m (→{{header|C++}}: pretty-printing of code) |
||
Line 56:
=={{header|C++}}==
<cpp>
</cpp>
It is also possible to add a constructor (this allows the use of <tt>Point(x, y)</tt> in expressions):
<cpp>
</cpp>
Point can also be parametrized on the coordinate type:
<cpp>
{
▲ template<typename Coordinate> struct point
▲ Coordinate x, y;
▲ };
▲ // A point with integer coordinates
▲ Point<int> point1 = { 3, 5 };
// a point with floating point coordinates▼
Point<float> point2 = { 1.7, 3.6 };▼
</cpp>
Of course, a constructor can be added in this case as well.
|