vector problem

This is a discussion on vector problem within the Game Programming forums, part of the General Programming Boards category; Ok so i have a particle class and particle generator class and in the generator class i have a vector ...

  1. #1
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195

    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??
    i am using DevC++

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    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 results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    the code is attatched here
    Attached Files Attached Files

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    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?

  5. #5
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    i dont really understand what you mean by your last post? sorry

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Maybe include <vector>?
    Woop?

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    ..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.
    Last edited by VirtualAce; 11-19-2005 at 12:47 AM.

  8. #8
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    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 , and thanks for all the help guys.

  9. #9
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    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 .
    Last edited by loopshot; 11-19-2005 at 05:53 PM.

  10. #10
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    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

  11. #11

    Join Date
    May 2005
    Posts
    1,041
    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.
    I'm not immature, I'm refined in the opposite direction.

  12. #12
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    ok sweet it worked thanks for everyones help

Popular pages Recent additions subscribe to a feed

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