c++ - linkedlist with class in the struct can't get bool operation working -


i can't seem boolean operation working thought works.

/////.h file  class linkd {    private: struct listnode{     driver driver;   ////class      listnode *next; }; listnode *head;  ///.cpp file    void linkd::deletenode(driver d){  listnode *nodeptr; listnode *previousnode; listnode *newnode; newnode=new listnode; newnode->next=null; newnode->driver=d;  if(!head)     return; if(head->driver==d) //the problem right here. {     nodeptr=head->next;     delete head;     head=nodeptr; } 

head->driver==d gives redline (no operator "==" matches these operands)

i think because head->driver uninitialized might wrong , not sure how initialize since it's inside uninitialized struct.

that's because driver class object.

you have define equality operator class.

are expecting class object pointer (as in java i.e. can null)

if want test driver objects equality define this:

class driver {     public:         bool operator==(driver const& rhs) const         {             return  x == rhs.x && y == rhs.y && z == rhs.z;         }     private:         int x;         int y;         int z; };  int test {      driver x;      driver y;       if (x == y)   // calls x.operator==(y)      {             // y rhs parameter.      } } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -