类的const static成员变量
#include<iostream>
using namespace std;
class test{
public :
test (int t,int v);
void print();
static void prin();
private :
const int a;
static int b;
int d;
const static int c ;
};
int test::b=10;
const int test::c=0;
test::test(int t = 0,int v = 1):a(t),d(v)//常量成员的初始化
{
b+=11;
}
void test::print()
{ cout<<"a"<<" "<<a<<endl;
cout<<"b"<<" "<<b<<endl;
cout<<"c"<<" "<<c<<endl;
cout<<"d"<<" "<<d<<endl;
}
void test ::prin(){
cout<<"c"<<" "<<c<<endl;
}
int main(){
test t;
t.print();
test f(6553,854);
f.print();
test::prin();
return 0;
}
浙公网安备 33010602011771号