Default parameter in constructor as object?

Hi

In case of normal variables I can do this:

1
2
3
4
5
6
7
8
9
10
11
Class Point
{
   float x,y,z;

   Point(float x=0.0f, y=0.0f, z=0.0f)
   {
      this->x=x;
      this->y=y;
      this->z=z;
   }
};


That is, default parameters x=0, y=0, z=0. But how can I add default parameter of constructor as object? In this case:

1
2
3
4
5
6
7
8
9
10
11
12
13
Point p1(0,0,0), p2(1,0,0), p3(0,1,0);

Class Triangle
{
   Point A, B, C;

   Triangle(Point a=p1, Point b=p2, Point c=p3)
   {
      this->A=a;
      this->B=b;
      this->C=c;
   }
};


Thanks
Last edited on
1
2
3
4
5
6
7
8
9
class Triangle
{
   Point A, B, C;
 public:
   Triangle(Point a = Point(0,0,0), Point b = Point(1,0,0), Point c = Point(0,1,0))
   : A(a), B(b), C(c)
   {
   }
};
Many thanks
Topic archived. No new replies allowed.