c++ 继承(杂)
来源:互联网 发布:西安汇知中学教师招聘 编辑:程序博客网 时间:2024/05/17 04:02
public是这个程序的每一处都能访问,无论是在本类内还本类外
protected则是在本类内和友类,子类中才能访问(只能在类的成员函数中调用 )
private则只能在本类内和友类才能访问,其它地方则不能(和protected 区别 ;不能在子类中访问)
class base
{
public:
int a;
void f(){
b;//true
c;//true
};
friend void pFun(const base&a);//声明友元函数 必须在外部定义
protected:
int b;
private:
int c;
}
void pFun(const base&a)
{
cout<<c;//true;
cout<<b;//true;
}
class Derive:public base
{
public:
void g(){
this->b;//ture(调用本类实例的 b)
__super::b;//true(调用基类的 私有数据)(或 this->base::b)
}
void f() {
}
private:
int c;
int b;
}
void main
{
base a;
a.a=2;//true
a.b=2;//error 只能在类的函数中调用
a.c=2;//error 同上
protected则是在本类内和友类,子类中才能访问(只能在类的成员函数中调用 )
private则只能在本类内和友类才能访问,其它地方则不能(和protected 区别 ;不能在子类中访问)
class base
{
public:
int a;
void f(){
b;//true
c;//true
};
friend void pFun(const base&a);//声明友元函数 必须在外部定义
protected:
int b;
private:
int c;
}
void pFun(const base&a)
{
cout<<c;//true;
cout<<b;//true;
}
class Derive:public base
{
public:
void g(){
this->b;//ture(调用本类实例的 b)
__super::b;//true(调用基类的 私有数据)(或 this->base::b)
}
void f() {
}
private:
int c;
int b;
}
void main
{
base a;
a.a=2;//true
a.b=2;//error 只能在类的函数中调用
a.c=2;//error 同上
pFun(a);//调用友元函数
}
- 【C++】继承(菱形继承)
- 【C++】继承(虚基类)
- (C++)多重继承
- 【转载】继承(C#)
- C++(继承篇)
- 【c++】(初识)继承
- 继承(C++)
- 继承---派生类(C++)
- object-c 学习(继承)
- c继承
- C++----------------继承
- 【c#】继承
- C++:继承
- C++::继承
- [C++]继承
- 【C++】继承
- 【C#】继承
- 【c++】继承
- Redis的安全性
- Java中类与类,类与接口直接的关系
- 【PAT】1042. Shuffling Machine (20)
- 设计模式-状态模式
- Mac OS X 10.9 Mavericks 正式版官方下载与改进
- c++ 继承(杂)
- 每天学点linux--(如何安装与卸载软件)
- 求阶乘n!----c语言版
- 一种自动反射消息类型的 Google Protobuf 网络传输方案
- pplive面试
- 对百度有点失望了
- ARM汇编基础
- hadoop bin 目录主要文件说明
- 数据结构之(图存储结构之)邻接表