Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

c++ vector curiosity

Options
  • 13-02-2006 1:38am
    #1
    Registered Users Posts: 1,105 ✭✭✭


    I've got a bit of an odd question regarding vectors in c++
    I'm not really that used to using them, I prefer to use arrays most of the time...

    I have designed and built a graph data structure for a project
    If I try to declare a vector in a .h file for a part of my data structure:
    #ifndef __VERTEX_H
    #define __VERTEX_H
    class Vertex;
    #include "edge.h"
    #include <vector>

    class Vertex{
    public:
    /*various functions...*/
    private:
    int ID;
    int degree;
    Edge *first;
    Edge *edges;
    vector<int> adjacentIDs; /* Vector declaration here!!!*/
    char Colour;
    };
    #endif

    the compiler screams at me and says:
    ../vertex.h:23: error: ISO C++ forbids declaration of ‘vector’ with no type
    ../vertex.h:23: error: expected ‘;’ before ‘<’ token

    yet when I declare a vector of ints in exactly the same way in my main.cpp there's no problem at all.
    anybody ever experienced this before?

    (using Eclipse, on linux, with the latest CDT plugin, same error when compiling on command line with make using gcc 4.0.1)


Comments

  • Registered Users Posts: 1,481 ✭✭✭satchmo


    vector and all the other STL containers are in the std namespace, so you need to either put using namespace std; at the top of the header file or (preferably) explicitly specify it's scope, ie:
    ...
    std::vector<int> adjacentIDs; /* Vector declaration here!!!*/
    ...
    


  • Registered Users Posts: 1,105 ✭✭✭larryone


    aaaah
    I had
    #include <iostream>
    using namespace std;
    at the top of my main.cpp, hence why it worked there.
    that is odd. - thanks a million satchmo =0)


Advertisement