Victor Hannak wrote:
> All the documentation I have looked through (the FAQ, textbooks) all show
> pure virtual functions declared as const.
No problem whatsoever.
Why not give it a go before posting ?
>
> Is there anything wrong with instantiating a non-const pure virtual
> function? What if I need the polymorphed version of the function to be able
> to modify private data members of the derived class? I wrote some code with
> the pure virtual function not defined as const, and it seems to work fine,
> but is this bad coding style? Why doesn't any of the documentation have
> examples like this?
Bad docs ?
>
> I understand why the definition of the pure virtual function in the ABC is
> const. After all, it can't/shouldn't do anything in the ABC. But if I make
> it const, then I also have to make the polymorphed versions of it const as
> well in order for the declaration to match, right? (Otherwise, it seems
> that the compiler does not see the relationship between the abstract and
> derived version of the function, and I get an error about my derived class
> also being an ABC)
>
class ABC
{
public:
virtual void F();
};
class DC : public ABC
{
public:
int x;
virtual void F()
{
x=1;
}
};
.... try that !
|