Skip to main content
Post Closed as "Duplicate" by mustaccio, Mateusz Grzejek, Captain Obvlious, bytecode77, πάντα ῥεῖ c++
added 382 characters in body
Source Link
Mateusz Grzejek
  • 12.3k
  • 3
  • 35
  • 52

I have a code like this. When run, it's return fault  : undefined reference to `A::x' A::x. How can iI fix this.?

http://cpp.sh/2flz

#include <iostream> using namespace std; class A { private: static int x; public: A(){ } A(int t) { x = t; } static void f() { cout<< A::x; } int f2() { return x; } }; int main() { A::f(); A a; a.f2(); } 

I have a code like this. When run, it's return fault  : undefined reference to `A::x' . How can i fix this.

http://cpp.sh/2flz

I have a code like this. When run, it's return fault: undefined reference to A::x. How can I fix this?

#include <iostream> using namespace std; class A { private: static int x; public: A(){ } A(int t) { x = t; } static void f() { cout<< A::x; } int f2() { return x; } }; int main() { A::f(); A a; a.f2(); } 
Source Link

undefined reference Static Member C++

I have a code like this. When run, it's return fault : undefined reference to `A::x' . How can i fix this.

http://cpp.sh/2flz