#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(); }
#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(); }