我有一個頭文件,我在其中聲明一個具有結構的類。另外我正在聲明一個重載操作符(!=,比較結構體)作爲這個類的成員。我在cpp文件中給出了這個運算符的定義。但我不能夠訪問結構的成員在類內的結構中使用運算符重載
car.h
class car
{
int carsor;
struct model
{
int id;
int mode;
}prev,curr;
bool operator !=(const model& model1);
};
car.cpp
#include "car.h"
bool car::operator !=(const model& model1)
{
if((model1.id==model.id)&&(model1.mode==model.mode))
{
return false;
}
else
{
return false;
}
}
我得到的錯誤是這樣
Error 2 error C2275: 'car::model' : illegal use of this type as an expression
如何我應該訪問結構成員嗎?
你想比較一個'汽車'與'模型',或者'模型'在他們自己之間? –
模型之間.. – raveesh