Francis Goblet wrote:[color=blue]
>
> RWCString& Interface::getName(void)
> {
> return name;
> }
>
> // Design class : Interface
> Interface::operator==(const Interface& inter)
> {
> return name==inter.getName();
> }
>
> \INTFACE.CPP(39) : error C2662: 'getName' : cannot convert 'this' pointer
> from 'const class Interface' to 'class Interface &' Conversion loses
> qualifiers[/color]
The "inter" parameter is const, but you invoke its "getName" member
function, which is not const, and therefore (as far as the compiler knows)
might try to modify inter's state. Try making getName a const member
function, like this:
RWCString& Interface::getName(void) const
{
return name;
}
Note the keyword "const" appears at the end of the function header. You
must also add the "const" keyword to the end of the function declaration
within the Interface class definition:
class Interface
{
// . . .
RWCString& getName(void) const;
// . . .
};
[color=blue]
> // Design hash function for Interface object
> unsigned hashInterface(const Interface& iface)
> {
> return iface.getName().hash();
> }
> \INTFACE.CPP(51) : error C2662: 'getName' : cannot convert 'this' pointer
> from 'const class Interface' to 'class Interface &' Conversion loses
> qualifiers[/color]
Same problem. Just make the modification I suggested above, and that should
fix things.
[color=blue]
> \INTFACE.CPP(51) : error C2228: left of '.hash' must have
> class/struct/union type[/color]
This error might simply be a consequence of the previous error.
Hope that helps,
Russell Hanneken
rhanneken@pobox.com