I have a header file where i am declaring a class with a structure within it. Also i am declaring an overloading operator(!=, to compare structures) as member of this class. I am giving the definition of this operator in the cpp file. But i am not able to access the members of the structure
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;
}
}
The error i get is this
Error 2 error C2275: 'car::model' : illegal use of this type as an expression
how should i access the the structure members?
if((model1.id==model.id)&&(model1.mode==model.mode))–modelis the name of your class and not your object. Your object is accessible viathisor you may omit it altogether inside the class.Use
if((model1.id==prev.id)&&(model1.mode==prev.mode))to compare withprevorif((model1.id==next.id)&&(model1.mode==next.mode))to compare with next.