Jump to content
  • Advertisement
Sign in to follow this  
Hunter_Ex

Inheritance

This topic is 4866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

lets say i have 2 classes Class Graphic Class Resource how can i derive them so both classes has acces to each others protected variables like Class Graphic : public Resource Class Resource : public Graphic but yea it might be impossible ill maybe make one class of them instead another problem is this lets say i have 2 classes ( hehe again) Class Window Class Graphic : public Window but when i tryed to use any of the protected variables in the Window class from my graphic class the variables is NULL or 0x0 why?? thx hunter_Ex

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
did you initialize the window variables in the constructor for graphic?
i.e.

public:
graphic(void) : window() { }
...

Share this post


Link to post
Share on other sites
i maked the window and stuff in the Window Class

like

[SOURCE]
Class Window
{
private :
protected :

HWND window;

public:

construct
deconstruct
etc...
}

Class Graphic : public Window
{
// wanna use the window handle but i only get a NULL result when i uses it
even if a window is created in the "window" variables why

i tryed manually get the window from a function from window and supply it to the graphic class and then it worked any clue??

}


[/SOURCE]


hunter_ex

Share this post


Link to post
Share on other sites
I'm not entirely sure what you're doing, but it sounds a bit like you're expecting an instance of the Graphics class to magically know about the data stored in a completely separate instance of the Window class.

Inheritance involves an 'is a' type relationship. If you derive Graphics from Window then an instance of the Graphics class will have all the functionality of the Window class in addition to it's own. However, the data for instances of these classes are all seperate, unless you're using static members.

Share this post


Link to post
Share on other sites
then whats wrong with this code :S



// this is only the header
class Window
{
private:

protected:

HWND window;

public:

inline void MakeWindow(char* caption) {
// psuedo code
create custom class
register class
createwindow
functions worked it created a window
};
};

class Graphic : public Window
{
public:

inline void CreateD3D() {
// psuedo code
CreateDevice(window);
};
};

// and now my little test file not a complete

#include <windows.h>
#include <d3dx9.h>
#include <the upper header.h>

Window form;
Graphic graph;

// here i start the Win Main ()
{
form.MakeWindow("test window);
// the window worked and the "window" variable is valid

// now set up d3d device
graph.CreateD3D();
// but this functions failes couse the derived functions "window" from class
//Window is NULL... WHY?


// etc.. the message handler
};






the window variable is declared and known in the graphic class but
the value is always NULL even if the "window" really is a window handle
with non NULL value

help plzz hunter_ex

[Edited by - Hunter_Ex on July 19, 2005 8:11:58 AM]

Share this post


Link to post
Share on other sites
Where is 'window' being set? How are you instantiating your 'Graphics' object? Are you also instantiating a 'Window' object?

Share this post


Link to post
Share on other sites
Ah, that confirms what I suspected.

form and graph are two completely separate objects. form is a 'Window' object. graph is both a 'Window' and a 'Graphics' object. Both have a member variable called 'window' but this is not shared between them, they are two completely separate variables.

Instead of calling form.MakeWindow(), just call graph.MakeWindow() instead. You don't need to create a separate 'Window' object, graph is already a 'Window' object in it's own right. You don't need 'form' at all.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!