保护继承
2016-06-09 22:02
218 查看
#define _CRT_SECURE_NO_WARNINGS 1 #include<iostream> using namespace std; class CBase1//定义基类 { public://定义公有型成员 void SetXY(int a, int b) { x1 = a; y1 = b; num1 = 10; } void Show() { cout << "在基类CBase1中,公有型变量y1的值为:" << y1 << endl; cout << "在基类CBase1中,公有型变量x1的值为:" << x1 << endl; cout << "在基类CBase1中,公有型变量num1的值为:" << num1 <<endl; } protected://定义保护型成员 int num1; private: int x1; int y1; }; class CDerivedl : protected CBase1//保护继承基类 { public: void SetValue() { SetXY(10, 20); num1 = 11; Show(); } }; int main() { CDerivedl d1;//定义派生类对象 d1.SetValue(); getchar(); return 0; }本文出自 “顺势而为” 博客,请务必保留此出处http://lk123456.blog.51cto.com/10831443/1759694
相关文章推荐
- 栈的应用 逆波兰式
- 迷宫问题
- python爬虫正方教务系统
- 运用JMeter登录系统,并进行性能测试
- Android 最火开发框架 xUtils
- 阿里云服务器,数据库热备、暖备、冷备实战-镜像篇(域环境下配置)
- 面向对象封装
- 模板实现双向链表
- 模板实现顺序表
- UNIX环境高级编程-第4章-4.8-4.10
- 最长递增子序列 nlogn
- 候选人得票统计程序
- 双向链表的几种实现
- 单链表的相关实现
- C语言顺序表的几种实现
- mysql登录用户验证遇到的问题 access denied for user ‘user’@'localhost'
- 《零售心理战》:711董事长总结的运营经验。三星推荐
- 天猫魔盘在ubuntu16.04中的使用
- 开发者必看的提高效率的在线工具
- hdu 1195(搜索)