最近程序中需要用到多线程工作下的单例模式.而其多种实现方法中,利用内部类实现懒汉模式是一种值得推荐的方式.顺便也就对内部类和外部类之间的关系做了一下研究,总结如下(理解不困难,不粘贴代码了,有需要的留言,我再做个demo). static成员与非static成员的访问:无论是外部类访问内部类的静态成员(变量和函数等),还是内部类访问外部类的静态成员,都不能用实例访问,必须用类本身访问:相应地,访问对方的非静态成员,则必须用实例访问.这与两个普通类之间的相互访问对方的static or non-s
在一个类中定义的类被称为嵌套类,定义嵌套类的类被称为外部类.; //不能访问 mytest::i = 10;//不能访问 } private: class mytest { int i; int j; }; }; 不能直接访问mytest的成员,试着通过对象访问. class test { public: test() { cc.i = 10; //通过对象可以访问,如果i为私有则不可访问 } private: class mytest { public: int i; int j; }; my
Nested classes are further divided into two types: static nested classes: If the nested class is static, then it’s called static nested class. Static nested classes can access only static members of the outer class. Static nested class is same as any