Good day. After compiling the code, an unresolved externals error pops up.
class Name { public: static int a; }; void main() { Name::a = 5; cout << Name::a << endl; system("pause"); }
Why? Deytel seems to say so
Good day. After compiling the code, an unresolved externals error pops up.
class Name { public: static int a; }; void main() { Name::a = 5; cout << Name::a << endl; system("pause"); }
Why? Deytel seems to say so
You can, just need to write correctly
#include <iostream> using namespace std; class Name { public: static int a; }; int Name::a = 5; int main() { cout << Name::a << endl; return 0; }
An error in the first line of main when referring to a declared but not defined static member of a class actually takes place (I initially overlooked it, the downsides in my direction are completely justified).
Secondly, try not to use the system ("pause") to stop the execution of the program, this is a system- dependent, unbearable, non- recommended method. For this purpose it is better to use the standard std :: cin.get () tool as follows:
#include <iostream> class Name { public: static int a; }; int Name::a = 5; int main() { Name::a = 5; std::cout << Name::a << std::endl; std::cin.get(); // system("pause"); }
std::cin.get()
also not needed. The console application either runs directly in the console, then such an overkill is not needed, or with a debugger, and there is a stub for this. - KoVadimSource: https://ru.stackoverflow.com/questions/553666/
All Articles