成员变量是引用类型的话,如何初始化
各位好:
定义类如下:
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 '请问各位如何解决该问题,感谢!!
[解决办法]
只能在初始化列表里面初始化,不能在构造函数体内初始化。