Posted November 29, 200519 yr I'm bashing my head into a wall over this one. I've got one main class, BitmapObject, which I'm trying to get derived classes from. I create a publically inherited class, PaddleObject, everything's just peachy. When I try to display it on a window using the GDI (BitBlt of an DC, Selected with a BITMAP), with a public funciton inside BitmapObject, it refuses to show itself. HOWEVER, when I make a BitmapObject, and use the very same function, the image appears in all it's glory. WHY THE FUCK IS THIS HAPPENING!?
November 29, 200519 yr Can you post the definition of the BitmapObject and PaddleObject classes? Would make it a bit easier to understand what you're aiming for and where you're having an issue.
November 29, 200519 yr erm not really sure whats going on but if you have an object and say create an instance of it newBoject = new object(); whatever then to show it u need newObject.show(); i know thats some thing u have to do in java. check the class your inheriting from to see what objects it allready has. this may be no help to you add all because i dont totaly know whats the problem
November 29, 200519 yr Lets say we have a member function Draw() in BitmapObject. Now, to inherit, we do this: class PaddleObject : public BitmapObject { // ... public: void Draw() const; // Exactly same declaration as in BitmapObject. // ... }; Then, to make the Draw function in PaddleObject, we can do like this: void PaddleObject::Draw() const { BitmapObject::Draw(); // Do whatever BitmapObject does // Here, do whatever extra you want PaddleObject to do (if you have nothing here, you might want to think about a different method than inheriting) }
November 29, 200519 yr Author Lets say we have a member function Draw() in BitmapObject. Now, to inherit, we do this: class PaddleObject : public BitmapObject { // ... public: void Draw() const; // Exactly same declaration as in BitmapObject. // ... }; Then, to make the Draw function in PaddleObject, we can do like this: void PaddleObject::Draw() const { BitmapObject::Draw(); // Do whatever BitmapObject does // Here, do whatever extra you want PaddleObject to do (if you have nothing here, you might want to think about a different method than inheriting) } So I have to retype the prototype plus the function when I inherit? What? I thought inhertiting meant that everything was inherited, including functions.
November 29, 200519 yr So I have to retype the prototype plus the function when I inherit? What? I thought inhertiting meant that everything was inherited, including functions. They are, and you don't have to define them again unless you're overriding the parent class' behavior. (or defining a virtual function, whatever) It would make more sense for the parent class to load a bitmap from a path stored in a variable in the class (char *), and simply have child classes redefine that variable in their contructor. (Even if it's set in the parent class' constructor, the child class' constructor will be called after the parent class' is called.) Then simply create instances of your child class to create a new bitmap object with the custom bitmap (defined in the constructor of the child class).
November 29, 200519 yr Author They are, and you don't have to define them again unless you're overriding the parent class' behavior. (or defining a virtual function, whatever) It would make more sense for the parent class to load a bitmap from a path stored in a variable in the class (char *), and simply have child classes redefine that variable in their contructor. (Even if it's set in the parent class' constructor, the child class' constructor will be called after the parent class' is called.) Then simply create instances of your child class to create a new bitmap object with the custom bitmap (defined in the constructor of the child class). Ok, when I get home, I'll try doing that.
November 29, 200519 yr All public and protected members are inherited. But, since i redefined the function, I had to redeclare it too. If the 2 classes have nothing in common, don't inherit. Usually, when you inherit you only EXTEND it's functionality. If you only redefine it's functionality, just rewrite everything.
November 29, 200519 yr Author Never mind, I changed it all around, and included the HDC and HTBIMAP variables and functions for each child class itself (which it turns out I needed to do anyway), and it's working fine now.
November 30, 200519 yr It's a good idea to plan out your OOP stuff ahead of time, that way you can find any discrepancies or areas where poor design might affect your app. The fewer ugly hax you have to do (like directly accessing member variables of a class), the better, as problems generally tend to snowball as the app grows in size/complexity. Glad to hear you sorted it out. :)