There is a class.
class some{ public: static int Instances; static int TotalSumm; public: some() { // Конструктор Instances = 0; } } This code is not collected. Mistake:
LNK2001 "Unresolved External Character".
What could be the problem?
There is a class.
class some{ public: static int Instances; static int TotalSumm; public: some() { // Конструктор Instances = 0; } } This code is not collected. Mistake:
LNK2001 "Unresolved External Character".
What could be the problem?
You declared a static field. But not defined .
Add
int some::Instances; int some::TotalSumm; out of class
After that, do you really need to reset the class member when creating each instance ?
Update . In order not to violate the rule of one definition, these definitions should be located in a single .cpp file, in a single copy. When placed in the header file, they will be defined in each .cpp file of the project ...
int some::Instances{5}; or int some::Instances = func(); or, if it is something more serious and has its own constructor - as when defining an object of the corresponding class. For example, suppose there is a class test with a constructor from two int , and in the class static test T; - then define as test some::T{12,18}; or something like that ... - Harrybecause you need to initialize outside the class
class some{ public: static int Instances; static int TotalSumm; public: some() { Instances = 0; } }; int some::Instances = 0; int main(int argc, char *argv[]) { some::Instances = 5; return 0; } Source: https://ru.stackoverflow.com/questions/525958/
All Articles