Property with pure virtual function

  • Thread starter Thread starter Adriano Coser
  • Start date Start date
A

Adriano Coser

Hi. I'm declaring a property on a base class that is represented by a
pure virtual function. Something like this:

public:
__declspec( property( get=GetWidth ) ) int Width;
virtual int GetWidth() = 0;

I'm implementing GetWidth in all subclasses, but I got the following
linker error:

QIVReport error LNK2001: unresolved external symbol "public: virtual
int __thiscall TMyAbstractClass::GetWidth(void)"
(?GetWidth@TMyAbstractClass@@UAEHXZ)

If I turn the function non-pure the error desapears.

Is there a way to use a pure virtual function to represent a property?

Thanks in advance for any help.

Regards,
Adriano.
 
Vince said:
a property cannot be a pure virtual function

But it seems like there is a relatively simple workaround (which I
haven't tested):

public:
__declspec( property( get=DoGetWidth ) ) int Width;
int DoGetWidth() { return GetWidth(); }
virtual int GetWidth() = 0;

DoGetWidth could probably be private, since there is no good reason (in
this particular case) to expose it. DoGetWidth and GetWidth should
probably be const member functions.
 
Hi. I'm declaring a property on a base class that is represented by a
pure virtual function. Something like this:

public:
__declspec( property( get=GetWidth ) ) int Width;
virtual int GetWidth() = 0;

I'm implementing GetWidth in all subclasses, but I got the following
linker error:

QIVReport error LNK2001: unresolved external symbol "public: virtual
int __thiscall TMyAbstractClass::GetWidth(void)"
(?GetWidth@TMyAbstractClass@@UAEHXZ)

If I turn the function non-pure the error desapears.

Is there a way to use a pure virtual function to represent a property?

You could try providing an implementation for the pure virtual
function (while leaving it pure virtual).

Tom.
 
Back
Top