#include < iostream. h >
class test{
private: static int x; int y;
public: void test1 ( int a, int b) { x = a; y = b; }
};
void main() {
test a;
a. test1 (2,3) ;
}
{X=A;Y=B;};错误,在类的非静态函数中不可直接访问类的静态成员。
#include < iostream. h >
class test{
private: static int x; int y;
public: void test1 ( int a, int b) { x = a; y = b; }
};
void main() {
test a;
a. test1 (2,3) ;
}
#include < iostream. h >
class test{
private: static int x; int y;
public: void test1 ( int a, int b) { x = a; y = b; }
};
void main() {
test a;
a. test1 (2,3) ;
}
{X=A;Y=B;};错误,在类的非静态函数中不可直接访问类的静态成员。