• 软件测试技术
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘

字号: | 推荐给好友 上一篇 | 下一篇

Google C++ Style Guide

发布: 2008-7-07 12:32 | 作者: Google | 来源: 领测软件测试网采编 | 查看: 229次 | 进入软件测试论坛讨论

领测软件测试网 软件测试技术门户I8pC8C:r;j)O5N+_

Nested Classes

Although you may use public nested classes when they are part of an interface, consider a namespace to keep declarations out of the global scope.
TC&c#~B0U link

Definition: A class can define another class within it; this is also called a member class.

class Foo {软件测试技术门户&I&O	r0xm1h
软件测试技术门户X4I*Lo0_;M!xN6_
private:
#V'U,veMf // Bar is a member class, nested within Foo.
%J"`%K? C| class Bar {软件测试技术门户D:KA-E.g6q a1c c
...
uJf5?,a:up$mp:F5Mg };
b&WBBFb v
bh.rt:AfN%gn#Q};
软件测试技术门户7S`UE4HyR5R%z2X

Pros: This is useful when the nested (or member) class is only used by the enclosing class; making it a member puts it in the enclosing class scope rather than polluting the outer scope with the class name. Nested classes can be forward declared within the enclosing class and then defined in the .cc file to avoid including the nested class definition in the enclosing class declaration, since the nested class definition is usually only relevant to the implementation. 软件测试技术门户'Uj_r1R c0jD t

Cons: Nested classes can be forward-declared only within the definition of the enclosing class. Thus, any header file manipulating a Foo::Bar* pointer will have to include the full class declaration for Foo.

ap7t]3yh

Decision: Do not make nested classes public unless they are actually part of the interface, e.g., a class that holds a set of options for some method.

`,{n.[2]@