Click to See Complete Forum and Search --> : Error in new class that base class is CObject


greene
April 21st, 1999, 03:58 AM
In VC++ 6.0,
I have been created a DLL in Regular DLL using shared MFC DLL.
I would like to create some new class that base class is CObject.
But when I compiled the DLL, errors was occured as follows.

class CMyApp : public CWinApp
{
public:
CMyApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGroveDLLApp)
//}}AFX_VIRTUAL

//{{AFX_MSG(CGroveDLLApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


class CMyObject : public CObject
{
public:
CMyObject();
CMyObject(Node node);

// Attributes
public:
Node* MyNode;
.....
.....
};



Error was occurred in CMyObject(Node node);.
Error message was "error C2629: unexpected 'class CMyObject ('".

How can I create a new class that base class is CObject?

Help me!

Franky Braem
April 21st, 1999, 04:44 AM
I also have that error sometimes. Most of the time the error means that there's something in your declaration that's not defined yet. I think that you haven't include the definition of your Node-class. If you don't want to include it then use a forward declaration like this : class Node;

Dave Lorde
April 21st, 1999, 04:48 AM
This is a typical misleading VC++ compiler error. It's actually telling you that it doesn't know what 'Node' is. You must provide a declaration of Node prior to your CMyObject declaration. If you pass the Node to the CMyObject constructor by reference, you can get away with just a forward declaration:

class Node; // Forward declaration - header can go in CMyObject .cpp file

class CMyObject : public CObject
{
public:
CMyObject();
CMyObject(Node& node); // Pass by reference avoids #including Node header

// Attributes
public:
Node* MyNode;
.....
.....
};

Hope this helps,

Dave