=?windows-1252?Q?Abstract_classes_=93interfaces=94_and_const_methods?=
From my understanding interfaces (like COM interfaces) are connectors
or messengers, they don?t do the job, but they ask someone else to do.
The same for member functions pointers.
Considering this, I don?t want to add into the message signature a
contract about the implementers if they will change or not their data
members.
In the object implementation I know if the method is const or not, and
I am happy to define this properly. I can use these members direclty
and the const will be usefull.
So what is the problem?
The problem is that virtual functions signature will depend on the
const.
For instance;
struct Interface {
virtual int GetSize() = 0;
};
struct Object : public Interface {
virtual int GetSize() const { return 1; }
}; // Error cannot instantiate abstract class
The solution adopted in COM is that the const is left out in the
object implementation.
I was thinking... I can use mutable in data members to say ?I don?t
care about const?.
So, should we have mutable for functions?
struct Interface {
virtual int GetSize() mutable = 0;
};
struct Object : public Interface {
virtual int GetSize() const { return 1; } //ok
};
struct Object2 : public Interface {
virtual int GetSize() { return 1; } //ok
};
struct Object : public Interface {
virtual int GetSize() { return 1; } //error
virtual int GetSize() const { return 1; }
};
Is there a better solution ?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]