Crazy error

Started by
2 comments, last by Antonym 15 years, 5 months ago
\visual studio 2005\projects\mud\mud\main.cpp(11) : error C2146: syntax error : missing ';' before identifier 'HP' \visual studio 2005\projects\mud\mud\main.cpp(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \visual studio 2005\projects\mud\mud\main.cpp(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int' #include <iostream> using namespace std; struct stats{ float HP; }stats; struct character{ stats HP; }; Why is it giving me the above error messages? I don't see anything wrong, that's all the code there is by the way so the error must be there. It's driving me insane.
Advertisement
You need:

struct stats{
float HP;
};
struct stats{float HP;}stats;
This defines a structure named 'stats', and an object of type 'stats' which is also named 'stats'. From then on, the name 'stats' refers to the object, not the type. Therefore, you cannot write stats HP; (although you could resolve the ambiguity with struct stats HP;).

On the other hand, why do you need an object named 'stats' at all?
I feel like such an enormous retard right now, the problem was so simple, I was trying to declare objects of type stats with another object of type stats. As for why I need that well it's a long story ;). Send me a pm we can be buddies.

This topic is closed to new replies.

Advertisement