读书人

成员变量是引用类型的话,怎么初始化

发布时间: 2012-03-06 20:47:55 作者: rapoo

成员变量是引用类型的话,如何初始化
各位好:
定义类如下:
class ReceiveRobInf : public ArASyncTask
{
protected:

double &myformationtype;

public:

ReceiveRobInf(int port, double* formationtype);
}
ReceiveRobInf::ReceiveRobInf(double* formationtype)
{

myformationtype=*formationtype;

}
运行后程序提示:error: uninitialized reference member 'ReceiveRobInf::myformationtype '请问各位如何解决该问题,感谢!!

[解决办法]
只能在初始化列表里面初始化,不能在构造函数体内初始化。

读书人网 >C++

热点推荐