-
vector problem
Ok so i have a particle class and particle generator class and in the generator class i have a vector of type particle and a iterator of that vector,
Code:
vector <Particle> Paticles;
vector <Particle>::iterator ParticlesIterator;
and when i complie i get the error:
ISO C++ forbids declaration or 'vector' with no type, and it highlights the lines of both of them
Particle.h is included as is std, What is going on?? :confused:
i am using DevC++
-
Hard to tell without seeing more of the code but are you sure you've added 'using namespace std' or equivalent in that file? Also are you sure you that you don't have a circular include problem? You could try storing the pointer to the object (which incidently, is the preferred way).
-
the code is attatched here
-
I can't see why it would do that but it's probably because I've had TOO much coffee. Can you please show the rest of the file that you are declaring the vectors?
-
i dont really understand what you mean by your last post? sorry
-
-
..and perhaps don't place a space between the vector and the type.
change:
Code:
vector <Particle> Particles;
to
Code:
vector<Particle> Particles;
Also do this to alleviate the multple include problem. I think you are experiencing this problem as well.
Code:
#ifndef CPARTICLE
#define CPARTICLE
...//declarations here
#endif //at end of include file
Do this for all your includes and this should fix the include problem. And you still must include <vector> in your code because even though the IDE understands what <vector> is, the compiler/linker will still fail to recognize it. The IDE is deceiving you into thinking since it knows the prototype for vector that you don't have to include it. Wrong. The IDE feature is just something nifty that MS included to aid you in programming so that you don't have to flip back and forth between the help file and/or include file and your source code file.
To test this theory use the Win32 TransparentBlt() function and attempt to link. The compiler will show you the prototype and everything, but it will fail to compile due to an unresolved external reference. Then link your code with msimg32.lib and it will work.
-
Alright bubba i will have to try that and see what i get, by the way guys sorry for late responses to your responses, i am in college and there is a lot of stuff i have to do befor i can even think about game programming every day so sorry :D , and thanks for all the help guys.
-
Wow bubba the suggestion took out compile time errors faster then i can say cat in a hat, and i can say it pretty fast :D .
-
so wait are you saying i need to do some thing like this:
Code:
#ifndef CPARTICLE
#define CPARTICLE
...//declarations here
#endif //at end of include file
at the beginning of every file in my project and for every class i have made? i am alittle confused
-
You really only need to do that for definition (header) files. Reason being, if you include the file more than once (like, if you include that file indirectly) the compiler will think you are also defining the data types more than once.
That is how I always begin writing a class definition in a header file:
#ifndef CLASSNAME_H
#define CLASSNAME_H
#endif
The CLASSNAME_H is just some macro name you choose...the compiler will associate that name with the contents of the header file. If you include the header file more than once, the compiler will only compile the first time it sees it, then it will just skip it because it's already been compiled.
-
ok sweet it worked thanks for everyones help