赞
踩
- #include <iostream>
-
- using namespace std;
-
- struct S1
- {
- char mA;
- int mB;
- };
-
- class C2
- {
- char mA;
- int mB;
- };
-
-
- int main(void)
- {
- S1 a;
- C2 b;
- cout<<sizeof(a)<<&a<<endl;
- cout<<sizeof(b)<<&b<<endl;
-
- getchar();
- return 0;
- }

- #include <iostream>
-
- using namespace std;
-
- struct S1
- {
- char mA;
- int mB;
- };
-
- class C1
- {
- char mA;
- int mB;
- };
-
- struct S2
- {
- char mA;
- int mB;
-
- void foo()
- {
- cout<<"mA="<<mA<<endl;
- cout<<"mB="<<mB<<endl;
- }
- };
-
- class C2
- {
- char mA;
- int mB;
-
- void foo()
- {
- cout<<"mA="<<mA<<endl;
- cout<<"mB="<<mB<<endl;
- }
- };
-
-
- int main(void)
- {
- S1 a;
- C1 b;
-
- S2 c;
- C2 d;
-
- cout<<sizeof(S1)<<"\t"<<&a<<endl;
- cout<<sizeof(C1)<<"\t"<<&b<<endl;
-
- c.foo();
- d.foo();
-
- getchar();
- return 0;
- }

1>e:\code\vs2010_prjs\struct\structdeclare\classandstruct.cpp(54): error C2248: “C2::foo”: 无法访问 private 成员(在“C2”类中声明)
1> e:\code\vs2010_prjs\struct\structdeclare\classandstruct.cpp(34) : 参见“C2::foo”的声明
1> e:\code\vs2010_prjs\struct\structdeclare\classandstruct.cpp(30) : 参见“C2”的声明
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。