Having difficulty resolving error

This is a discussion on Having difficulty resolving error within the C++ Programming forums, part of the General Programming Boards category; Hello everyone. I have tried my best to remedy this error that I am having. I've been working on a ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Having difficulty resolving error

    Hello everyone. I have tried my best to remedy this error that I am having. I've been working on a game engine and have written 200 files, but for some reason this one is giving me trouble. I'm sure its something arbitrary that I'm not seeing. I'm getting these errors in VS 2008:
    error C2146: syntax error : missing ';' before identifier 'rect'
    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    The Rectangle file is:
    Code:
    #ifndef RECTANGLE_H
    #define RECTANGLE_H
    
    #include "MathHeader.h"
    #include "Vector3.h"
    
    class Rectangle
    {
    public:
    	Rectangle(void);
    	Rectangle(const Vector3& center, const Vector3* axes, const real* halfWidths);
    	~Rectangle(void);
    
    	Vector3 closestPointToRect(const Vector3& point);
    
    	Vector3 center;
    	Vector3 axes[2];
    	real halfWidths[2];
    };
    #endif
    and the header file that uses the rectangle is:
    Code:
    #ifndef CONSOLE_H
    #define CONSOLE_H
    
    #include "WindowsGLIncludes.h"
    #include "AbstractGameObject.h"
    #include "MathHeader.h"
    #include "Rectangle.h"
    #include "Vector3.h"
    #include "HardwareBufferManager.h"
    
    class Console : public AbstractGameObject
    {
    public:
    	Console(void);
    	Console(const int& width, const int& height, const Vector3& center);
    	virtual ~Console(void);
    
    	void update();
    	void animate(real elapsedSeconds);
    	void render();
    
    	Rectangle rect;
    };
    #endif
    I don't know why its having trouble understanding the rectangle type. If anyone can give me assistance I would be very grateful.

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    I can post the source files if that would make it easier to find.
    Thanks,
    Adam

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,017
    You need to look at what lines those error occur. All those error should be easy to fix if you look at the line they occur on.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    It's coming from the declaration of the rectangle object in the Console class. I have already checked that and just about everything else. The compiler doesn't think the rectangle class exists for some reason, but the class compiles fine. I have tried multiple classes to try and get an instance of the rect class and it will always throw the same errors. Here is my rectangle source:
    #include "Rectangle.h"

    Code:
    /**
    	Default constructor
    */
    Rectangle::Rectangle(void)
    {
    
    }
    
    /**
    	Constructor to initialize attributes
    */
    Rectangle::Rectangle(const Vector3& center, const Vector3* axes, const real* halfWidths)
    {
    	this->center = center;
    	for (int i = 0; i < 2; i++)
    	{
    		this->axes[i] = axes[i];
    	}
    	for(int i = 0; i < 2; i++)
    	{
    		this->halfWidths[i] = halfWidths[i];
    	}
    }
    
    /**
    	Default destructor
    */
    Rectangle::~Rectangle(void)
    {
    
    }
    
    /**
    	Finds the closest point on a rectangle to a given point in space.
    */
    Vector3 Rectangle::closestPointToRect(const Vector3 &point)
    {
    	Vector3 q;
    	Vector3 d = point - this->center;
    
    	q = this->center;
    
    	for (int i = 0; i < 2; i++) 
    	{
    		//distance from axis to center
    		real distance = d.dot(this->axes[i]);
    
    		//clamp to rect if distance exceeds it
    		if (distance > this->halfWidths[i]) 
    			distance = this->halfWidths[i];
    		if (distance < -this->halfWidths[i]) 
    			distance = -this->halfWidths[i];
    
    		//get world coordinate
    		q += this->axes[i] * distance;
    	}
    
    	return q;
    }

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    Does anyone here have any suggestions? I still get the same errors when I do a forward declaration of the rectangle class. All of my ideas have ran dry.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,311
    Quote Originally Posted by danriver22
    I still get the same errors when I do a forward declaration of the rectangle class.
    A forward declaration is not good enough enough since the Console class a Rectangle object as a member (as opposed to a pointer or reference to Rectangle). Therefore, the definition of the Rectangle class must be known at the definition of the Console class. You probably should include the header that contains the definition of the Rectangle class.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    Well the way I tried it originally was what I posted, which did include the Rectangle header. I tried the forward declaration in desperation to try and resolve this issue. I did make the rectangle a pointer when I did that though. I still can't figure out why the compiler doesn't see the rectangle class. The code looks all well and good to me. Any other ideas?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21