converting queue to linked list when using operator== c++ -
i have queue , linked list. trying call operator== function in linked list through queue function. assignment asking me compare 2 queues , see if same. have included functions each file giving me trouble.
the error message i'm getting "c2664 'bool list::operator ==(list &)': cannot convert argument 1 'const q' 'list &'"
queue.h
class q { public: q(); q(const q &queue); ~q(); bool operator==(const q &queue); private: list queue; };
queue.cpp
q::q(){}//constuctor q::q(const q &queue){}//copy constructor q::~q(){}//deconstuctor bool q::operator==(const q &queue1)//this problem { return queue.operator==(queue1); }
list.h
class list { private: struct node { int data; node* next; node() : next(null) {} //define our own default constructor node(int data) : next(null), data(data) {} }; typedef struct node* noderef; noderef head; noderef tail; noderef iterator; noderef current1; int size; public: list(); ~list(); list(const list &list); bool operator==(list &queue);// have problem };
list.cpp
bool list::operator==(list& queue) { if (size != queue.size) return false; iterator = head; noderef temp = queue.head; while (iterator != null) { if (iterator->data != temp->data) return false; temp = temp->next; iterator = iterator->next; } return true; }
main.cpp
q k,qw; if (k == qw) cout << "lists equal!\n"; else cout << "lists unequal!\n";
please help.
you need compare like, in case q
has queue
element (which list
), when comparing objects of type q
, need compare queue
elements.
as have operator ==
list
class, straightforward.
bool q::operator==(const q &queue1) { return queue == queue1.queue; }
Comments
Post a Comment