中文就是那么搅,,,,,,很清楚的东西要反复说......到头来搞得不清楚,,,,
几段代码编译一下就知道了:
#include<iostream>
using namespace std;
class A{
public:
void fun1() { cout<<"aaaa"<<endl;}
private:
void fun2() {cout<<"bbbbb"<<endl;}
protected:
void fun3() { cout<<"cccc"<<endl;}
};
/* int main(void)
{
A a;
a.fun1(); //OK
a.fun2(); //Wrong
a.fun3(); //Wrong
return 0;
} */
// 加上继承
class B: public A{
public:
void fun4() {cout<<"ssssss"<<endl;}
void fun5() { fun2(); } //Wrong, fun2在B类不可见
void fun6() { fun3(); } //OK, fun3在B类为protected
};
int main(void)
{
Ba;
a.fun1(); //OK
a.fun4(); //OK
a.fun6(); //OK
return 0;
}
还有很多情况,,就不一一说了...