If you are facing problems implementing the operator overloading of the stream extraction operator "<<", then note the following:
To summarize, if you add the following inside the DLList class, your program should compile correctly:
friend ostream & operator<<(ostream & out, DLList<T> & list) {
// code that prints the list should go here.}
On the other hand, overloading the assignment operator "=" can be done as usual, as a member or a non-member function and inlined or not inlined. In all cases it should work fine.
Here are two links if you wish to read more:
http://www.parashift.com/c++-faq-lite/template-friends.html
http://stackoverflow.com/questions/9814345/cant-overload-operator-as-member-function
- The function should be a non-member function. Overloading it as a member function should cause compilation errors when you implement the main function.
- The function should be inlined (i.e. implemented inside the class).
- To be able to access the private members of class DLList, the operator overloading function should be a friend of DLList.
To summarize, if you add the following inside the DLList class, your program should compile correctly:
friend ostream & operator<<(ostream & out, DLList<T> & list) {
// code that prints the list should go here.}
On the other hand, overloading the assignment operator "=" can be done as usual, as a member or a non-member function and inlined or not inlined. In all cases it should work fine.
Here are two links if you wish to read more:
http://www.parashift.com/c++-faq-lite/template-friends.html
http://stackoverflow.com/questions/9814345/cant-overload-operator-as-member-function
No comments:
Post a Comment