Abstract class ...
Mike Smolinski -- smolinsk@mpr.ca
Monday, November 25, 1996
Hi all...
Environment: VC++ 1.5 / Windows 3.1
(Don't fret... I'm switching to NT in December!!!!)
I created an Abstract Class (IE a class with a pure virtual function in
it), and I want it's subclasses to use the macro DECLARE_DYNCREATE.
I keep getting compile time errors. When I compile the version below,
the macro IMPLEMENT_DYNCREATE( CBaseClass ) inserts a "new CBaseClass()"
in the code which is illegal because it is an abstract class.
And, if I take out the macro pair (IMPLEMENT_DYNCREATE, DECLARE_DYNCREATE)
from CBaseClass, I get an error about CBaseClass not being set up with the
macros I just removed. Sorry, but I don't have access to the actual
error numbers/messages right now.
I tried the other macros ( DECLARE_??? ) as well. My problem
is that all these macos insert dynamic creation code which is illegal in
the case of CBaseClass.
For now, I just removed the "=0" at the end of all my pure virtual
functions, but I would really like to get this right.
Has anybody done this before? Have I over-looked something?
Any help would be very very very very much appreciated.
An example of my code is below... (ignore any syntax errors as I'm doing
this from (lack of) memory :) )
//****************************************
class CBaseClass : CObject
{
public:
CBaseClass::CBaseClass();
CBaseClass::~CBaseClass();
DECLARE_DYNCREATE( CBaseClass ) //* Add Serial/Runtime stuff and
//* dynamic create stuff.
virtual void blah( void) = 0; //* Pure virtual function
};
class CSubClass : CBaseClass
{
public:
CSubClass::CSubClass();
CSubClass::~CSubClass();
DECLARE_DYNCREATE( CSubClass ) //* Add Serial/Runtime stuff and
//* dynamic create stuff.
virtual void blah( void); //* Override for Pure virtual function
};
//****************************************
... Now in the .cpp file I put this...
IMPLEMENT_DYNCREATE( CBaseClass, CObject )
CBaseClass::CBaseClass()
{
}
CBaseClass::~CBaseClass()
{
}
IMPLEMENT_DYNCREATE( CSubClass, CBaseClass )
CSubClass::CSubClass()
{
}
CSubClass::~CSubClass()
{
}
void blah( void)
{
TRACE( "Blah\n" );
}
//****************************************
Thanks...
Mike
---
I want to die peacefully, in my sleep, like my grandfather, not
screaming, terrified, like his passengers.
---
Maurice Perry -- maurice@gespower.ch
Thursday, November 28, 1996
use DECLARE_DYNAMIC(CBaseClass) and IMPLEMENT_DYNAMIC(CBaseClass,CObject)
----------
> From: Mike Smolinski
> To: mfc-l@netcom.com
> Subject: Abstract class ...
> Date: lundi 25 novembre 1996 19:34
>
> Hi all...
>
> Environment: VC++ 1.5 / Windows 3.1
> (Don't fret... I'm switching to NT in December!!!!)
>
> I created an Abstract Class (IE a class with a pure virtual function in
> it), and I want it's subclasses to use the macro DECLARE_DYNCREATE.
>
> I keep getting compile time errors. When I compile the version below,
> the macro IMPLEMENT_DYNCREATE( CBaseClass ) inserts a "new CBaseClass()"
> in the code which is illegal because it is an abstract class.
>
> And, if I take out the macro pair (IMPLEMENT_DYNCREATE,
DECLARE_DYNCREATE)
> from CBaseClass, I get an error about CBaseClass not being set up with
the
> macros I just removed. Sorry, but I don't have access to the actual
> error numbers/messages right now.
>
> I tried the other macros ( DECLARE_??? ) as well. My problem
> is that all these macos insert dynamic creation code which is illegal in
> the case of CBaseClass.
>
> For now, I just removed the "=0" at the end of all my pure virtual
> functions, but I would really like to get this right.
>
> Has anybody done this before? Have I over-looked something?
> Any help would be very very very very much appreciated.
>
>
> An example of my code is below... (ignore any syntax errors as I'm doing
> this from (lack of) memory :) )
>
> //****************************************
>
> class CBaseClass : CObject
> {
> public:
> CBaseClass::CBaseClass();
> CBaseClass::~CBaseClass();
>
> DECLARE_DYNCREATE( CBaseClass ) //* Add Serial/Runtime stuff and
> //* dynamic create stuff.
> virtual void blah( void) = 0; //* Pure virtual function
> };
>
> class CSubClass : CBaseClass
> {
> public:
> CSubClass::CSubClass();
> CSubClass::~CSubClass();
>
> DECLARE_DYNCREATE( CSubClass ) //* Add Serial/Runtime stuff and
> //* dynamic create stuff.
> virtual void blah( void); //* Override for Pure virtual function
> };
>
> //****************************************
>
> ... Now in the .cpp file I put this...
>
> IMPLEMENT_DYNCREATE( CBaseClass, CObject )
>
> CBaseClass::CBaseClass()
> {
> }
>
> CBaseClass::~CBaseClass()
> {
> }
>
> IMPLEMENT_DYNCREATE( CSubClass, CBaseClass )
>
> CSubClass::CSubClass()
> {
> }
>
> CSubClass::~CSubClass()
> {
> }
>
> void blah( void)
> {
> TRACE( "Blah\n" );
> }
>
> //****************************************
>
>
>
> Thanks...
> Mike
>
> ---
> I want to die peacefully, in my sleep, like my grandfather, not
> screaming, terrified, like his passengers.
> ---
| Вернуться в корень Архива
|