现在的位置: 首页 > 综合 > 正文

google c++ style 笔记

2014年02月24日 ⁄ 综合 ⁄ 共 653字 ⁄ 字号 评论关闭

1. Headfile Dependecies

 

    How can we use a class Foo in a header file without access to its definition?(只用其声明,不用其定义。)

  • We can declare (but not define) functions with arguments, and/or return values, of type Foo. (One exception is if an argument Foo or const Foo& has a non-explicit, one-argument constructor,
    in which case we need the full definition to support automatic type conversion.)

为什么不能有non-explicit, one-argument constructor?如果有这样的函数,那么在一个源文件中调用这样的函数,那么就需要提供定义来支持支持这样的转换。如果没有这样的函数,只有到了链接的时候,才需要链接这个函数,而这个函数的定义在类的实现文件中(.cc,.cpp文件)。所以没有类型的转换需求,在编译阶段可以不需要类型定义。

  • We can declare static data
    members of type Foo. This is because static data members are defined outside the class definition.

什么时候需要类的定义?需要这个类型,来定义一个对象的时候,用指针引用了对象成员的时候。

 

抱歉!评论已关闭.