class A {
private:int x;
static int i;
};
int x int= x;10;
int A::i = x;
When I compile the code above, it get the error
<source>:8:12: error: invalid use of non-static Adata a;member 'A::x'
8 | int A::i static= intx;
i;
public:
| A(int y){ ^
<source>:2:9: note: declared here
2 | std::cout<<y<<std::endl;int x;
| }
};
int x = 10;
A a(x);
int A::i = x;^
I have a problem when I execute the above codes. It shows the “invalid use of non-static data member ‘A::x’”。 I have no idea aboutWhat's causing this problem, Could anyone give me helperror?