I am trying to pass a nested struct type as an argument for the class constructor, and use an initializer list to invoke the implicit copy constructor for the struct to do all the work. But it's somehow not working.
This is my header file
and this is my implementation of the classCode:#ifndef _OBJECT_HPP_ #define _OBJECT_HPP_ class Object { public: // Nested structure to represent a point and its corresponding operations struct Point { float x, y; // Struct constructor Point ( float X = 0, float Y = 0 ); // Way to set the point void Set ( float X, float Y ); // The origin static const Point ORIGIN; }; // Constructor Object ( const Point & center ); // Function for viewing and setting the center of the object Point & Center (); // Function for returning the area, a pure virtual function virtual float Area() const = 0; // Drawing function virtual void Draw (); // Destructor virtual ~Object(); private: Point center; }; #endif
The red part is where I am having problem, when I tried to compile I got this messageCode:#include "Object.hpp" const Object::Point Object::Point::ORIGIN = Object::Point(); // Point constructor Object::Point::Point ( float X, float Y ) { x = 0; y = 0; } // Set function void Object::Point::Set ( float X, float Y) { x = X; y = Y; } // Object constructor (default and non-default) // Use implicit copy constructor Object::Object ( const Point & center ) : Point(center) { } // Function for returning the area, a pure virtual function float Object::Area() const { } // Drawing function void Object::Draw () { } // Destructor Object::~Object() { }
Does a struct come with a default copy constructor or do I need to define it separately?Code:error C2436: 'Point' : member function or nested class in constructor initializer list
Please advice, thanks.



LinkBack URL
About LinkBacks


