我遇到了错误,我无法弄清楚原因。
我有一个子类:(标题)
class motionSensor: public sensorLeaf
{
public:
motionSensor(const int& sensorID, const int& sensorType, bool sensorActivate);
继承自超类" sensorLeaf"
子类有2个私有变量
const float minDistance;
const float maxDistance;
在我的班级文件中;这是我的构造函数:
motionSensor::motionSensor(const int &sensorID, const int &sensorType, bool sensorActivate)
:sensorLeaf(sensorID, sensorType, sensorActivate), minDistance{1.0f}, maxDistance{5.0f}
但是一旦我编译它,我就会得到以下错误:
/home/jb/EmergencySensor/motionsensor.cpp:8: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
:sensorLeaf(sensorID, sensorType, sensorActivate), minDistance{1.0f}, maxDistance{5.0f}
^
Sensorleaf构造函数是:
sensorLeaf::sensorLeaf(const int sensorID, const std::string sensorType, bool sensorActivate)
{
_sensorID = sensorID;
_sensorType = sensorType;
_sensorActivate = sensorActivate
}
使用私有变量:
private:
int _sensorID;
std::string _sensorType;
bool _sensorActivate;
};
在做了一些研究之后,我发现当你将一个字符串定义为' '而不是" "但是我没有在任何地方使用它。
答案 0 :(得分:1)
您正试图从const int &sensorType
构造函数强制motionSensor
到const std::string sensorType
sensorLeaf
构造函数。{/ p>
motionSensor::motionSensor(const int &sensorID, const int &sensorType, bool sensorActivate)
------------------------------------------------------------^
:sensorLeaf(sensorID, sensorType, sensorActivate), minDistance{1.0f}, maxDistance{5.0f}
-----------------------^
sensorLeaf::sensorLeaf(const int sensorID, const std::string sensorType, bool sensorActivate)
-------------------------------------------------------------^