CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    5

    Error in new class that base class is CObject

    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!



  2. #2
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Error in new class that base class is CObject

    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;


  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: Error in new class that base class is CObject

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured