Thread: static vector<...> in class problem.

  1. #1
    alkis_y3k
    Guest

    Unhappy static vector<...> in class problem.

    Okay, I've been struggling around with this for a day, I cannot find the solution. Here is my class declaration:

    Code:
    class CRTLight
    {
    public:
        CRTLight() {Lights++; }
        ~CRTLight() {Lights--; } 
    
        void Pu****();    
        static int Lights;
        static vector<CRTLight*> vList;
    
    };
    and my cpp file:
    Code:
    int CRTLight::Lights = 0;
    
    void CRTLight::Pu****()
    {
        vList.push_back(this);
    }
    The compiler (VC++6) complains:
    rLight.obj : error LNK2001: unresolved external symbol "public: static class std::vector<class CRTLight *,class std::allocator<class CRTLight *> > CRTLight::vList" (?vList@CRTLight@@2V?$vector@PAVCRTLight@@V?$alloc ator@PAVCRTLight@@@std@@@std@@A)
    ../bin/rEngine.dll : fatal error LNK1120: 1 unresolved externals

    But if I remove the push_back call, it is ok, but i need the call
    Any ideas?

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Nevermind, I found it.
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  3. #3
    Registered User newbie_grg's Avatar
    Join Date
    Jul 2002
    Posts
    77
    did you include main function()??i got that sort of unresolved external error when i forgot to include main function
    "If knowledge can create problems, it is not through ignorance that we can solve them. "
    -Isaac Asimov(1920-1992)

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    funny. You're Push_it() (remove the underscore) got censored.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Originally posted by newbie_grg
    did you include main function()??i got that sort of unresolved external error when i forgot to include main function
    I think he included main()
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    No, the problem was that he didn't do this:

    vector<CRTLight*> CRTLight::vList;

    in the cpp file.

    If it were main that was missing, it would have said the function main, but it said vList, so vList was missing.

    You only get an error if you use it, just like if you used a function without defining it. It's a linking problem, not a compile problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. uploading file to http server via multipart form data
    By Dynamo in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2008, 04:36 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Using private class members in static functions
    By sethjackson in forum C++ Programming
    Replies: 2
    Last Post: 09-23-2005, 09:54 AM
  5. Static variables and functions problem in a class
    By earth_angel in forum C++ Programming
    Replies: 16
    Last Post: 09-15-2005, 12:08 PM