linked list - nested node class operator overload < c++ -


this question has answer here:

i'm trying overload < operator nested node class inside linkedlist class. have setup this:

linkedlist<t>::node& linkedlist<t>::node::operator<(const linkedlist<t>::node& rhs){     return rhs;  } 

but error 1>c:\users\kevin\workspace\linkedlist\linkedlist.h(185): warning c4183: '<': missing return type; assumed member function returning 'int'

i try return 1 doesn't work either.

node dependent name, need use typename tell compiler referring type.

template <typename t> const typename linkedlist<t>::node&  linkedlist<t>::node::operator<(const typename linkedlist<t>::node& rhs) 

also, note have const reference, returning non-const one. should return const reference, in real code, confusing operator< not return bool. make more sense:

template <typename t> bool linkedlist<t>::node::operator<(const typename linkedlist<t>::node& rhs) const 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -