Advertisement

Problem with headers and classes.

Started by July 31, 2001 01:31 PM
0 comments, last by Roof Top Pew Wee 23 years, 6 months ago
I am trying to create my own GUI with my own line and square classes that plot themselves with functions. Everything was fine and I have the objects put in a header called ddstructs.h . In another file, called LegendsGUI.h, I have created some objects which are child classes of the base shapes. Here's the code: //ddstructs.h class line : public graphicsObject // holds ddsd and basic stuff { // left out because everything here works fine }; // end of line class class square {public: // left stuff out. Again everthing is fine square(bla bla bla) // constructor works fine void drawSquare()// again works fine }; // end of ddstructs.h Now the problem: // legendsGUI.h // I made this class just to test inheritance between header // files #include "ddstructs.h" class superSquare : public square { public: superSquare(){}; superSquare(int top, int bottom, int left, int right, int width, int r, int g, int b, DDSURFACEDESC2* DDsd) { square(top, bottom, left, right, width, r, g, b, DDsd); }; void drawSuper() { drawSquare(); } }; My program includes the "LegendsGUI.h" file which includes the "ddstructs.h" file. In my main program, I can create a square or line and everything works fine, but when I try to create a superSquare, I get no errors, but neither my drawSuper() nor my superSquare::drawSquare() functions will work. Any ideas as to why it won't work? I am pretty sure it has to do with the inheritance being between two headers, but I can't figure out what. My EMail is VChelaru@hotmail.com if it is a complicated explanation. Thanks in advance. --Vic-- Edited by - Roof Top Pew Wee on July 31, 2001 2:33:36 PM Edited by - Roof Top Pew Wee on July 31, 2001 2:36:14 PM
In your superSquare constructor, don't manually call the constructor for Square, instead do it with an initializer list:

superSquare(int top, int bottom, int left, int right, int width, int r, int g, int b, DSURFACEDESC2* DDsd) : square(top, bottom, left, right, width, r, g, b, DDsd)
{

};


- Matt



Edited by - 3dModelMan on July 31, 2001 3:10:40 PM

This topic is closed to new replies.

Advertisement