Derived Class: What are the rules ?
-
Greetings All, I have a CBitmap object and wish to derive a CTiledBitmap from it ? What do I have to consider: Do i have to use virtual Constructor/Destructor ? Can I just have CBitmap as a member of CTiledBitmap ? Any advice of how-to for derived classes ? Cheers If sex is a pain in the ass, then you are doing it wrong!
-
Greetings All, I have a CBitmap object and wish to derive a CTiledBitmap from it ? What do I have to consider: Do i have to use virtual Constructor/Destructor ? Can I just have CBitmap as a member of CTiledBitmap ? Any advice of how-to for derived classes ? Cheers If sex is a pain in the ass, then you are doing it wrong!
An useful question when considering whether you should model your new class as derived from some base class is the following: A
CTiledBitmap
is aCBitmap
? Or put another way: If I change all occurrences ofCBitmap
withCTiledBitmap
in a preexisting program, will the program still work? I guess the answer in your particular case is no. Please note that the interface ofCBitmap
is not virtual, so the class is not designed with derivation in mind. Probably, a better design is to derive yourCTiledBitmap
fromCGdiObject
and haveCBitmap
as a private member. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
An useful question when considering whether you should model your new class as derived from some base class is the following: A
CTiledBitmap
is aCBitmap
? Or put another way: If I change all occurrences ofCBitmap
withCTiledBitmap
in a preexisting program, will the program still work? I guess the answer in your particular case is no. Please note that the interface ofCBitmap
is not virtual, so the class is not designed with derivation in mind. Probably, a better design is to derive yourCTiledBitmap
fromCGdiObject
and haveCBitmap
as a private member. Joaquín M López Muñoz Telefónica, Investigación y DesarrolloThanks The CBitmap is a class of mine: should probably call it CMyBitmap ? it has it's own constructor, loader and draw function. So A CMyTiledBitmap is a CMyBitmap with some extra members (for the tiling info). So, If I change all occurrences of CMyBitmap with CMyTiledBitmap in a preexisting program, the program will still work, but will have greater resource overhead. So Why do I make the CMyBitmap constructor virtual ? Cheers If sex is a pain in the ass, then you are doing it wrong!