博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++嵌套类
阅读量:7208 次
发布时间:2019-06-29

本文共 1209 字,大约阅读时间需要 4 分钟。

C++支持类的嵌套,其语法比较简单。代码是最好的说明。

1 #include 
2 using namespace std; 3 4 class Outter{ 5 public: 6 int a; 7 static int s; 8 //nested class and enclosing class are independent. 9 class Inner{ 10 public:11 int b;12 //nested class can access static members of enclosing class13 int foo(){ return b + s;}14 int bar();15 };16 };17 18 int Outter::s = 1;19 //define a nested class member outside of the class declaration.20 int Outter::Inner::bar(){21 return 0xdeadbeef;22 }23 24 int main(){25 Outter o;26 o.a = 0;27 //if nested class is specified as public, then everyone can use the nested class.28 //if nested class is specified as protected, then only the enclosing class,29 //friend of the enclosing class and derived class of the enclosing class can access the nested class.30 //if the nested class is specified as private, then only the enclosing class31 //and friend of the enclosing class can access the nested class.32 Outter::Inner i;33 i.b = 1;34 cout<
<

 

转载于:https://www.cnblogs.com/richardustc/archive/2013/04/26/3045166.html

你可能感兴趣的文章
c# 的传递参数值传递与传递引用的区别,ref与out区别
查看>>
win7+vs2008+cuda5.x 环境配置二
查看>>
PHP5.5安装PHPRedis扩展
查看>>
c#Socket Tcp服务端编程
查看>>
java构造函数注意点
查看>>
Asp.net 中配置 CKEditor和CKFinder
查看>>
Use dynamic type in Entity Framework 4.1 SqlQuery() method
查看>>
《Python CookBook2》 第四章 Python技巧 - 若列表中某元素存在则返回之 && 在无须共享引用的条件下创建列表的列表...
查看>>
redhat网卡设置
查看>>
javascript 的作用域
查看>>
JFinal极速开发框架使用笔记(二) 两个问题,一个发现
查看>>
AutoCompleteTextView
查看>>
SecureCRT生成序列
查看>>
Android 应用程序主框架搭建
查看>>
2012腾讯春季实习生面试经历(二)
查看>>
用Bootstrap框架弹出iframe页面 在弹出的模态框中载人iframe页面,bootstrapiframe
查看>>
2012腾讯暑期实习面经(技术类web前端)
查看>>
第3种方法获取redis cluster主从关系
查看>>
注册表管理(本地、远程)
查看>>
《Linux内核设计与实现》第四周读书笔记——第五章
查看>>