Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Constructor overloading (http://www.go4expert.com/forums/constructor-overloading-t25728/)

student19 7May2011 16:53

Constructor overloading
I need to use function overloading to :

Accept all co-ordinates as arguments and set data members to match.

I don't know how to accept the co-ordinates as arguments and how to set the data members to match. Any advice would be good thanks

I have 3 classes , class 1Dpoint class2dpoint and class3dpoint. 1dcontains data member x, 2d contains x and y and 3d contains x,y and z. I have to use multiple constructors as means of function overloading. currently i have constructors : point1d, point2d and point3d. I have already started function overloading, and i have accepted no parameters and set co-ordinates to 0 ( well i think what i have done is correct). And my next step is the one above.


class 1DPoint    // The base Class
 1DPoint() // No parameters
 1DPoint(int x) // One parameter

    int x = 0;

    ~point1DClass();    //Destructor function

class 2DPoint: public 1DPoint
2DPoint() // No Parameter
2DPoint(int x, int y) // Two Parameters

    int y = 0;

    ~point2DClass();    //Destructor function


class 3DPoint : public 2DPoint
3Dpoint()// No Parameter
3DPoint(int x, int y, int z) // Three Parameters

  int z = 0;

 ~point3DClass();    //Destructor function
point3DClass::point3DClass(int x, int y, int z)
  x = 0;
  y = 0;
  z = 0;


int main ()


return 0;

All times are GMT +5.5. The time now is 04:01.