Pinte Laurentiu
Pinte Laurentiu

Reputation: 43

C2061 error: 'identifier', but I included the header?

I am working on a VC++ project (nothing Visual just using Visual Studio for editing). And in one of my classes i have a bunch of C2061 errors apearing, but evreything is fine, i double and triple checked. this is the class where the errors occur: Circle.h:

#ifndef __SGE__Circle__
#define __SGE__Circle__
#include <GLFW/glfw3.h>
#include "Vector2.h"
#include "Rectangle.h"
class Circle
{
public:
    Circle();
    Circle(float xCenter, float yCenter, float radius);
    Circle(Vector2& center, float radius);
    ~Circle();
    bool Contains(Vector2& point);
    bool Contains(Rectangle& rectangle); //ERROR OCCURS HERE
    bool Contains(Circle& circle);
    bool isContained(Rectangle& rectangle); //ERROR OCCURS HERE
    bool Intersects(Rectangle& rectangle); //ERROR OCCURS HERE
    bool Intersects(Circle& circle); 
    float Radius;
    Vector2 Center;
};
#endif

the error are like this :error C2061: syntax error : identifier 'Rectangle' and they apear everywhere Rectangle is called

Rectangle class looks like this:

Rectangle.h:

#ifndef __SGE__Rectangle__
#define __SGE__Rectangle__
#include <GLFW/glfw3.h>
#include "Vector2.h"
class Rectangle
{
public:
    Rectangle();
    Rectangle(float x, float y, float width, float height);
    Rectangle(Vector2& position, Vector2& size);
    ~Rectangle();
    Vector2* getCorners();
    Vector2 getCenter();
    bool Contains(Vector2& point);
    bool Contains(Rectangle& rectangle);
    bool Intersects(Rectangle& rectangle);
    float X;
    float Y;
    float Width;
    float Height;
};
#endif

And i also import both Circle.h and Rectangle.h in my main.cpp

and for fun :) Vector2.h:

#ifndef _SGE_Vector2_
#define _SGE_Vector2_
#include <GLFW/glfw3.h>
#include <math.h>
class Vector2
{
public:
    Vector2();
    Vector2(float x, float y);
    bool operator == (const Vector2& a);
    bool operator != (const Vector2& a);
    Vector2 operator +(const Vector2& a);
    Vector2 operator +=(const Vector2& a);
    Vector2 operator -(const Vector2& a);
    Vector2 operator -=(const Vector2& a);
    Vector2 operator *(const float a);
    Vector2 operator *=(const float a);
    Vector2 operator /(const float a);
    Vector2 operator /=(const float a);
    float Length();
    void Normalize();
    ~Vector2();
    GLfloat X;
    GLfloat Y;
};
#endif

Upvotes: 0

Views: 927

Answers (1)

Pinte Laurentiu
Pinte Laurentiu

Reputation: 43

The "GLFW/glfw3.h" contains a function: bool Rectangle(...); which creates errors when class Rectangle is used. There are 2 solution for this problem:

  1. Rename class Rectangle to something else ex: Rect
  2. Create a namespace that contains all the classes making posible to call

using namespace X; //X is replaced by the name of your namespace

in main overriding the Rectangle function with the Rectangle class .

The problem was solved with Sarang's help!

Upvotes: 1

Related Questions