Thread: static class functions and variables not playing nicely

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    static class functions and variables not playing nicely

    Why am I getting undefined refferances to all my static members of the class? Even if I chop it all down to just the LOADED = ture; line I still get an undefined refferances.

    Code:
    class Some_Class
    {
    public:
    static void LOAD_DATA(char *data_file_path)
      {
          LOADED = true;
          ifstream stream;
          stream.open(data_file_path);
          stream>>nmbr;
          infolist = new weapon_info*[nmbr];
          for(int i=0;i<nmbr;i++)
          {
             infolist[i] = new weapon_info;
             stream>>infolist[i]->id
                   >>infolist[i]->mdmg
                   >>infolist[i]->xdmg
                   >>infolist[i]->range
                   >>infolist[i]->speed
                   >>infolist[i]->hands;
          }
      }
    
      private:
      static int nmbr;
      static bool LOADED;
      static weapon_info **infolist;
      int min_dmg, max_dmg;
      int hands;
      int speed;
      int range;
    
    };

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Static members must also be declared independently...outside the class...because no memory is allocated for them (all, not only the static ones...but the others get it from objects) when the compiler goes through the class declaration...

  3. #3
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Ahh ok I see thanks. Makes sense now that I think about how things work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling non-static functions on static variables
    By pandu in forum C++ Programming
    Replies: 14
    Last Post: 06-19-2008, 03:07 AM
  2. Static variables in functions
    By tretton in forum C Programming
    Replies: 1
    Last Post: 04-08-2006, 06:49 AM
  3. Question about Static variables and functions.
    By RealityFusion in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2005, 02:31 PM
  4. 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
  5. Static variables in functions
    By PJYelton in forum C++ Programming
    Replies: 2
    Last Post: 10-04-2002, 01:41 PM