Having problems vector again. I'm studying static data members and doing a toy class to further my knowledge. This class has a single data member and several static members. I placed a few comments to better illustrate the class. The idea... to have a class that records the sum and average of its objects.
The constructor is being defined on the class cpp file. Also shown, the static members initialization.Code:class counter { public: counter(int); inline int value() const; //number getter //static members getters inline static unsigned long count(); inline static unsigned long sum(); inline static double avg(); static double ravg(unsigned long x); //pass vector index, return avg. private: int number; static unsigned long count_; //object count static unsigned long sum_; //sum of counter::number static double avg_; //average of counter::number static std::vector<double> ravg_; //holds running average }; /* inline definitions are here */
Why am I getting an unresolved external in the constructor pointing to the ravg_.push_back() line?Code:unsigned long counter::count_ = 0; unsigned long counter::sum_ = 0; double counter::avg_ = 0; std::vector<double> ravg_(1, 0); counter::counter(int x = 0): number(x) { count_ += 1; sum_ += x; avg_ = static_cast<double>(sum_) / static_cast<double>(count_); ravg_.push_back(avg_); //unresolved external error }