#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    UK
    Posts
    119
    Rep Power
    12

    Lightbulb Class dependancy issue


    I have two classes one called Vector4 and one called Point. They are defined basically as follows:

    Code:
    class Vector4{
    	
    	public:
    
    		float c[4];
    }
    
    class Point
    {
    	public:
    		float c[3];
    }
    I have a member function of Point that will do Point - Vector4 and it goes like this

    Code:
    Vector4 Point::operator- (const Vector4& p) const
    {	
    	return Vector4(	c[0]-p.c[0],
    					c[1]-p.c[1],
    					c[2]-p.c[2]);
    }
    I would like to do the same thing for Vector4 - Point sothe first thing I would think of is to make a member function in Vector4 but Point hasnt been defined by then so it throws a compile error. How can I add a function to Point to do this or how can I get arround the depndency problem
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,179
    Rep Power
    2222
    Do a forward declaration:
    Code:
    class Point;
    
    class Vector4{
    	
    	public:
    
    		float c[4];
                                    Point  operator- (const Point& p) const;
    };
    
    class Point
    {
    	public:
    		float c[3];
                                    Vector4 operator- (const Vector4& p) const;
    };
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    UK
    Posts
    119
    Rep Power
    12
    simple as that eh? Cheers :)

IMN logo majestic logo threadwatch logo seochat tools logo