Thread: Base class initialization

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    Base class initialization

    Ok I've got a huge class hierarchy here and I'm getting myself confused over what's going on.

    Here is the structure.

    Code:
    class D3D {};
    class DirectDraw {};
    class DXGraphics:public D3D, public DirectDraw {};
    
    class DXInput {};
    class DXMouse:public DXInput {};
    
    class DXEngine:public DXGraphics,public DXInput {};
    
    class TileEngine:public DXEngine {};
    All constructors contain no code -> just default constructors.
    The Init() function of each class actually inits the class -> left out for clarity's sake.

    Here is my problem. Let's say I wanted to use the mouse. The mouse requires the DirectInput object to be created first. Then you use that object to then create the Mouse object. The Mouse object requires you to pass the HINSTANCE of the application so that it can set the priority level for this instance.

    Problem with this setup is that I cannot create a mouse at all. What is happening when I instantiate TileEngine? Does it not instantiate DXMouse? Since I know it does, how then do I actually create the Mouse object. Every time I try to place a pointer to the mouse object inside of TileEngine and instantiate it, I get an illegal operation message box - or the code simply exits with no error. Since DXMouse is actually a part of TileEngine, why should I even include a class pointer to DXMouse? How do I actually create the DXMouse object?

    Here is what happens when I instantiate TileEngine.

    D3D is instantiated.
    DirectDraw is instantiated.
    DXGraphics is instantiated.
    DXInput is instantiated.
    DXMouse is instantiated.
    DXEngine is instantiated.

    It's easy to use DirectDraw and D3D because these are mere function calls. Hmm. Maybe I just answered my own question. Since I can directly use DirectX and D3D from TileEngine could I also not just directly use the mouse with no pointer? In other words simply call its functions to use it?

    All this inheritance crapola is for the birds. Perhaps I will use pointers to these objects instead of deriving from everything and using multiple base classes.
    Last edited by VirtualAce; 01-10-2004 at 09:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual base class
    By George2 in forum C++ Programming
    Replies: 7
    Last Post: 03-14-2008, 07:45 AM
  2. derived class can not access base class protected member?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2007, 06:32 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Can't Access the private member from base class
    By planet_abhi in forum C# Programming
    Replies: 3
    Last Post: 01-09-2006, 04:30 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM