Relative Content

Tag Archive for c++static

What is the reason why static member values cannot be used in constructors in different project?

I have a static link library project A, which contains files MyClass.h and MyClass.cpp. It defines a class and I want to use static member variables in the constructor. I have defined another project B to test this static link library and found that using the value of static member variables in the constructor and initializing the value of static member variables outside the class. If it is an int type, this value is initialized and accessible, but if it is a std: string or other non primitive type, the value does not exist. Why is this happening. Here are project A MyClass.h:
A MyClass.h:

What is the reason why static member values cannot be used in constructors?

Using the value of a static member variable in a constructor, initializing the value of the static member variable outside the class. If it is of type int, the value is initialized and accessible, but if it is of type std:: string or other non primitive types, the value does not exist. Why is this.
Here are my header files and CPP files:

What is the reason why static member values cannot be used in constructors?

Using the value of a static member variable in a constructor, initializing the value of the static member variable outside the class. If it is of type int, the value is initialized and accessible, but if it is of type std:: string or other non primitive types, the value does not exist. Why is this.
Here are my header files and CPP files: