类数据成员初始化
类中私有成员是静态字符串的数据成员,要怎样对其初始化呢
2016-04-11 18:40
2016-04-11 19:49
2016-04-11 20:23
程序代码:#include <iostream>
#include<string>
using namespace std;
class a{
public:
void print(){std::cout<<s<<std::endl;}
private:
static string s;
};
string a::s;
int main()
{
a b;
b.print();
}

2016-04-11 20:42
2016-04-11 21:05
2016-04-11 21:08
程序代码:#include <iostream>
#include<string>
using namespace std;
class a{
public:
void print(){std::cout<<s<<std::endl;}
private:
static string s;
};
string a::s("abc"); //调用string类带参数的构造函数
int main()
{
a b;
b.print();
}

2016-04-11 21:22