Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Class inheritance problems

Class inheritance problems

Scheduled Pinned Locked Moved C / C++ / MFC
c++oophelpquestionannouncement
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi! I can't derive my CBaseRenderer class from CD3DBase, here's my code:

    #pragma once

    class CD3DBase;

    class CBaseRenderer : public CD3DBase
    {
    public:
    CBaseRenderer(void);
    ~CBaseRenderer(void);

    public:
    void OnLostDevice();
    void OnResetDevice();
    void OnFrameMove();
    void OnRender();
    void OnInitVolatileResources();
    void OnFreeVolatileResources();
    };

    and these are the errors: ------ Build started: Project: DXProject, Configuration: Release Win32 ------ Compiling... CBaseRenderer.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined DXProject.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined CD3DBase.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined CApplication.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined What's wrong with this code? :( regards

    J 1 Reply Last reply
    0
    • L Lost User

      Hi! I can't derive my CBaseRenderer class from CD3DBase, here's my code:

      #pragma once

      class CD3DBase;

      class CBaseRenderer : public CD3DBase
      {
      public:
      CBaseRenderer(void);
      ~CBaseRenderer(void);

      public:
      void OnLostDevice();
      void OnResetDevice();
      void OnFrameMove();
      void OnRender();
      void OnInitVolatileResources();
      void OnFreeVolatileResources();
      };

      and these are the errors: ------ Build started: Project: DXProject, Configuration: Release Win32 ------ Compiling... CBaseRenderer.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined DXProject.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined CD3DBase.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined CApplication.cpp e:\C++\DXProject\CBaseRenderer.h(7) : error C2504: 'CD3DBase' : base class undefined What's wrong with this code? :( regards

      J Offline
      J Offline
      Johnny
      wrote on last edited by
      #2

      You must include the header for the definition of CD3DBase. If you are deriving from a class then it is not enough just to have a forward reference, you need the full class available.

      L 1 Reply Last reply
      0
      • J Johnny

        You must include the header for the definition of CD3DBase. If you are deriving from a class then it is not enough just to have a forward reference, you need the full class available.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Ok thanks, but if I include the header, I get even more errors, since CBaseRenderer and CD3DBase include each other, because CD3DBase needs to create an object of CBaseRenderer

        J 1 Reply Last reply
        0
        • L Lost User

          Ok thanks, but if I include the header, I get even more errors, since CBaseRenderer and CD3DBase include each other, because CD3DBase needs to create an object of CBaseRenderer

          J Offline
          J Offline
          Johnny
          wrote on last edited by
          #4

          You could put a forward declaration of CBaseRenderer into CD3DBase.h

          L 1 Reply Last reply
          0
          • J Johnny

            You could put a forward declaration of CBaseRenderer into CD3DBase.h

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Ok, next errors :-D

            #pragma once

            /* includes */

            class CBaseRenderer;

            class CD3DBase
            {
            /* ... */
            private:
            CBaseRenderer gRenderer;
            };

            And here the errors: e:\C++\DXProject\CD3DBase.h(46) : error C2079: 'CD3DBase::gRenderer' uses undefined class 'CBaseRenderer

            D 1 Reply Last reply
            0
            • L Lost User

              Ok, next errors :-D

              #pragma once

              /* includes */

              class CBaseRenderer;

              class CD3DBase
              {
              /* ... */
              private:
              CBaseRenderer gRenderer;
              };

              And here the errors: e:\C++\DXProject\CD3DBase.h(46) : error C2079: 'CD3DBase::gRenderer' uses undefined class 'CBaseRenderer

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              You're missing #include "BaseRenderer.h" or you can make gRenderer a pointer.


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              L 1 Reply Last reply
              0
              • D David Crow

                You're missing #include "BaseRenderer.h" or you can make gRenderer a pointer.


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                tried both. this eliminated all errors, except that now I get this one again: e:\C++\DXProject\CBaseRenderer.h(5) : error C2504: 'CD3DBase' : base class undefined

                #pragma once
                #include "CD3DBase.h"

                class CBaseRenderer : public CD3DBase
                { ...

                but well...since I only need a pointer to an IDirect3DDevice9 from CD3DBase, I might also create a function to pass this one as a parameter and make CBaseRender not to inherit from CD3DBase.

                S 1 Reply Last reply
                0
                • L Lost User

                  tried both. this eliminated all errors, except that now I get this one again: e:\C++\DXProject\CBaseRenderer.h(5) : error C2504: 'CD3DBase' : base class undefined

                  #pragma once
                  #include "CD3DBase.h"

                  class CBaseRenderer : public CD3DBase
                  { ...

                  but well...since I only need a pointer to an IDirect3DDevice9 from CD3DBase, I might also create a function to pass this one as a parameter and make CBaseRender not to inherit from CD3DBase.

                  S Offline
                  S Offline
                  suiram40
                  wrote on last edited by
                  #8

                  you have a dependecy loop. "a.h" file includes "b.h" and "b.h" file includes "a.h" when you derive the derivated class has to know the type tou derive from so you need the definition of the type not the declaration of that type.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups