Protected 的static 成员在MSDN上看了关于protected 权限的文档,有一段话不明白,求解释Protected members
Protected 的static 成员
在MSDN上看了关于protected 权限的文档,有一段话不明白,求解释
Protected members that are also declared as static are accessible to any friend or member function of a derived class. Protected members that are not declared as static are accessible to friends and member functions in a derived class only through a pointer to, reference to, or object of the derived class.
参考连接:http://msdn.microsoft.com/en-us/library/e761de5s(v=vs.110).aspx
[解决办法]
class Parent
{
protected:
string strTest;
};
class Child:public Parent
{
public:
Child(string strMsg)
{
this->strTest = strMsg;
}
void PrintMsg()
{
cout<<strTest<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Child chdClass("hello");
chdClass.PrintMsg();
system("pause");
return 0;
}
