Thread: using vectors

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    using vectors

    Hi,
    I am having some trouble using vectors:

    I declared a vector as follows in my header file as a private data member:

    std::vector<CNode> adapterVector;

    But when I try to add an element to it in the .cpp file,
    it seems the ide (MSVS .NET 2003) does not recognize the name

    For example if I write
    adapterVector.

    it should give me a list of member function but it does not.
    Any insight would be highly appreciated.
    Thanks
    Amish

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    post code
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    This happens from time to time with me where for whatever reason my MSVC++ refuses to give me a pull down list for a declared object. Usually its because theres some parsing problem above it that confuses it, even if it compiles just fine. If you compile, do you get an undeclared variable error?

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    A private data member doesn't have member functions; an instantiation of the class does.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> post code
    I believe that axr0284 is having problems with his IDE not expanding the members listbox after typing "adapterVector.".

    I don't use .NET 2003, but I do use VisualAssist, which is an awesome plug-in for most of the MSVS products.

    gg

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by Codeplug
    >> post code
    I believe that axr0284 is having problems with his IDE not expanding the members listbox after typing "adapterVector.".
    i was just being an ass becuase i didn't know the answer
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Thanks for the answer.
    It seems I had to make it a global variable to make it work. my .cpp file contains this outside of any function:
    Code:
    vector <CNode *> videoAdapterVector;
    If I used
    Code:
    static vector <CNode *> videoAdapterVector;
    instead in the .h file, it did not work.

    Can someone explain the difference between the two different approach. Thanks
    Amish

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You should NOT, and I repeat; should NOT define variables in a header files. Those goes into the body (cpp).

    If you still need the variable to be reached from other files that includes the header, put an extern in front of it.

    Ex:

    Yada.h:
    Code:
    extern int yatta;
    Yada.cpp:
    Code:
    int yatta;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  4. How to use Vector's in C++ !?!
    By IndioDoido in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2007, 11:13 AM
  5. Points, vectors, matrices
    By subnet_rx in forum Game Programming
    Replies: 17
    Last Post: 01-11-2002, 02:29 PM