How do I create a list of lists?

Article ID: 1067
Last updated: 05 Feb, 2008
Article ID: 1067
Last updated: 05 Feb, 2008
Revision: 1
Views: 2926
Posted: 24 Sep, 1997
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


I try to create a list of lists like this: RWTPtrDlist<RWTPtrDlist> xyz; but the compiler responds with errors indicating problems with operator==.

 




Cause


Any type used to parameterize RWTPtrDlist (and RWTValDlist, RWTPtrSlist and RWTValSlist as well) must have an operator== defined: int T::operator == (const T&) const. The class RWTPtrDlist (and RWTValDlist, etc) does not implement the == operator, thus parameterizing RWTPtrDlist with another may cause compiler errors. Some compilers insist on having a matching definition for every declaration in a templatized class, even if the method or operator is never used. Other compilers will ignore the lack of implementation and compile the code successfully.


Action


The solution is to derive from the list class and provide an == operator:
 template  class Dlist :    public RWTPtrDlist 
{
public:
int operator == (const T& list) const
{ return 0; }
};
and then create the list of lists:
RWTPtrDlist< Dlist > xyz;
or
RWTValDlist< Dlist > xyz;

The return value from Dlist::operator== can be constant as it is above, or you can fully implement the test for equality if you wish.

 

 

 

 

 

 

 

 

This article was:   Helpful | Not helpful
Report an issue
Article ID: 1067
Last updated: 05 Feb, 2008
Revision: 1
Views: 2926
Posted: 24 Sep, 1997 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category