compilation problems with static data member

This is a discussion on compilation problems with static data member within the C++ Programming forums, part of the General Programming Boards category; I am getting some problems with compiling the following code. It gives me the following error. I think its ver ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    1

    compilation problems with static data member

    I am getting some problems with compiling the following code.
    It gives me the following error. I think its ver staright forward and its just that I am missing something. pls help.

    I want to access statis data member which is an array of some other class type.
    error message:

    CalculateMovieSimilarity.cpp.text+0x3ce): undefined reference to `CalculateMovieSimilarity::ifileObject'
    CalculateMovieSimilarity.cpp.text+0x4a7): undefined reference to `CalculateMovieSimilarity::ifileObject'
    CalculateMovieSimilarity.cpp.text+0x547): undefined reference to `CalculateMovieSimilarity::ifileObject'
    collect2: ld returned 1 exit status


    and following is the code snippet

    Code:
    class IndexFileObject
    {
        public: int count;
                int referencebytepos;
                int relativebytepos[DATEINTERVALS];
    
    };
    
    
    class CalculateMovieSimilarity
    {
        public: static string indexfilename;
                static IndexFileObject ifileObject[17770];            
                static void createifileObject();
    
    };
    
    
    void CalculateMovieSimilarity::createifileObject(){
    
            CalculateMovieSimilarity::ifileObject[moviecount].relativebytepos[index]=atoi(relativebytepos.c_str());
      }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Do you have an actual instance of that static class data member somewhere in your source file?
    Code:
    CalculateMovieSimilarity::IndexFileObject ifileObject[17770];
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  3. Static member data inaccessible
    By BSTRhino in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2002, 08:28 PM
  4. Replies: 2
    Last Post: 09-29-2001, 03:36 PM
  5. How do I base size of arrays on annother number?
    By Dual-Catfish in forum C++ Programming
    Replies: 15
    Last Post: 09-25-2001, 01:31 PM

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