Thread: Problem constructing a class with a nested struc

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    21

    Problem constructing a class with a nested struc

    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

    Code:
    #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
    and this is my implementation of the class
    Code:
    #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()
    {
    }
    The red part is where I am having problem, when I tried to compile I got this message
    Code:
    error C2436: 'Point' : member function or nested class in constructor initializer list
    Does a struct come with a default copy constructor or do I need to define it separately?
    Please advice, thanks.
    Last edited by pliang; 04-14-2005 at 07:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  2. Inheritance using Stack Class Problem
    By dld333 in forum C++ Programming
    Replies: 17
    Last Post: 12-06-2005, 11:14 PM
  3. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM