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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

c++ vector curiosity

  • 13-02-2006 12:38am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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