static class functions and variables not playing nicely

This is a discussion on static class functions and variables not playing nicely within the C++ Programming forums, part of the General Programming Boards category; Why am I getting undefined refferances to all my static members of the class? Even if I chop it all ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    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...
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



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

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