hello_world.cpp 1>D:\002_Project\006_Visual_Studio\HelloWorld\HelloWorld\hello_world.cpp(30,5): error C2248...参见“MyClass”的声明 1>D:\002_Project\006_Visual_Studio\HelloWorld\HelloWorld\hello_world.cpp(33,5): error C2248...参见“MyClass”的声明 1>D:\002_Project\006_Visual_Studio\HelloWorld\HelloWorld\hello_world.cpp(36,5): error C2248
这些成员函数可以在子类中重写或复用 , 以便让子类能够访问和操作基类的私有成员 ; 如果在 子类 中 尝试访问 父类 的 私有成员 , 会报如下错误 : Test.cpp(34,1): error C2248
show(A a) { cout<<a.num<<endl; } int main() { A obj; show(obj); } 这个程序在VS2017环境下编译不通过,得到如下错误:error C2248
a.num<<endl; } int main(){ A obj; show(obj); getchar(); } 这个程序在VS2012环境下编译不通过,得到如下错误:error C2248
a1, a2; A a3(a1); cout << A::GetACount() << endl; cout << a1.GetACount() << endl; // 编译报错:error C2248
GetACount () << endl; 42 43 // 编译报错: error C2248: “A::_scount”: ⽆法访问 private 成员 ( 在 “A” 类中声明
static int _scount; int _a = 1; }; //类外面初始化 int A::_scount = 0; int main() { // 编译报错:error C2248
_stuNum << endl; } int main() { Person p; Student s; // 编译报错:error C2248: “Student::_stuNum”: ⽆法访问
< endl; } int main () { Person p; Student s; // 编译报错: error C2248
, a2; A a3(a1); cout << A::GetACount() << endl; cout << a1.GetACount() << endl; // 编译报错:error C2248
_stuNum << endl; } int main() { Person p; Student s; // 编译报错:error C2248: “Student::_stuNum”: 无法访问
// 尝试访问子类的保护成员,编译错误 } int main() { Person p; Student s; Display(p, s); // 编译报错:error C2248
来访问静态成员变量和静态成员函数 cout << A::GetACount() << endl; cout << a1.GetACount() << endl; // 编译报错:error C2248
领取专属 10元无门槛券
手把手带您无忧上云