Re: Cannot instantiate abstract class by Victor
Victor
Wed Jun 08 22:06:27 CDT 2005
Tim Roberts wrote:
> Tom Widmer <tom_usenet@hotmail.com> wrote:
>>
>> Igor Tandetnik wrote:
>>> "Rubio" <jtnim@hotmail.com> wrote:
>>>
>>>> Why do I get C2259: 'Derived': cannot instantiate abstract class
>>>> from the following scenario?
>>>>
>>>> class Abstract
>>>> {
>>>> public:
>>>> virtual int GetType() = 0;
>>>> virtual int GetApp() = 0;
>>>> virtual void GetVersion() = 0;
>>>> ...
>>>> }
>>>>
>>>> class Derived : public Abstract
>>>> {
>>>> public:
>>>> int GetType();
>>>> int GetApp();
>>>> void GetVersion(LPTSTR versio, size_t versionSize);
>>>> ...
>>>> }
>>>>
>>>> In class 'Derived' I've written an implementation for all three
>>>> pure virtual methods.
>>>
>>>
>>> No you have not. You have provided overrides of GetType and
>>> GetAttr, but you simply overloaded GetVersion.
>>
>> No overloading here - GetVersion in Derived has hidden GetVersion in
>> Abstract.
>
> Perhaps you could explain what you mean, because I think you are
> wrong.
You think wrong.
> The signature of Derived::GetVersion is different from
> Abstract::GetVersion. Both Derived::GetVersion and
> Abstract::GetVersion are visible in Derived,
Actually, no. Read about name hiding in C++.
> which is what caused the
> problem in the first place.
No. The problem is that 'GetVersion' has no final overrider.
> Defining a new method with the same name but a different signature is
> exactly the way I would define "overloading".
Too bad.
Overloading works _only_ in the same scope. As soon as nested scopes
are involved, _hiding_ is taking over. You need to read the archives on
the difference between "overloading", "hiding", and "overriding". Keep
in mind that the derived class' scope is considered _nested_ in the base
class' scope.
V