读书人

类对象的有关问题

发布时间: 2013-09-07 14:12:44 作者: rapoo

类对象的问题
我想问一个问题,以前只知道用,可是今天想想有点不对。
作为类函数的参数我们用引用而不可以用对象是因为没有定义完整类型的原因,但是我在类定义中使用对象却可以,我指的是直接在类中,我有点不明白,这难道不是使用了不完整类型吗??这是为什么??
[解决办法]
那是应为只是定义而已,只是形式参数而已!不是实际参数。
如果你调用这个接口的时候,传递类的对象的时候,
就需要实例化对象来进行调用传递实际参数啦
[解决办法]
这个是标准的特惠。c++11 9.2/2
A class is considered a completely-defined object type (3.9) (or complete type) at the closing } of the class-specifier. Within the class member-specification, the class is regarded as complete within function bodies, default arguments, exception-specifications, and brace-or-equal-initializers for non-static data members (including such things in nested classes). Otherwise it is regarded as incomplete within its own class member-specification.

[解决办法]
类的初始化过程需要关注

读书人网 >C++

热点推荐