Reputation: 677
I was trying to compile simple class declaration using the guide form this page.
http://www.cplusplus.com/doc/tutorial/classes/
It was pasted straight from the website and would not allow me to compile. I am using visual studio 2010.
This is the error I received:
error C2146: syntax error : missing ';' before identifier 'rec'
Changing the name of class solved the problem, but I could not find anywhere that Rectangle is a word reserved for anything VS or C++ related.
How could I work that out next time?
class Rectangle
{
public:
int width;
int height;
};
int main( )
{
Rectangle rec;
}
class Rector
{
public:
int width;
int height;
};
int main( )
{
Rector rec;
}
Upvotes: 1
Views: 396
Reputation: 4850
If you include Windows.h or Wingdi.h, your class name likely conflicts with the Rectangle function.
You have several options:
Rectangle
class in a namespaceclass Rectangle
everywhere to disambiguate between the function and the class (as a last resort)Upvotes: 3