Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Derived Class: What are the rules ?

Derived Class: What are the rules ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wogerdoger
    wrote on last edited by
    #1

    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!

    J 1 Reply Last reply
    0
    • W wogerdoger

      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!

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      An useful question when considering whether you should model your new class as derived from some base class is the following: A CTiledBitmap is a CBitmap? Or put another way: If I change all occurrences of CBitmap with CTiledBitmap in a preexisting program, will the program still work? I guess the answer in your particular case is no. Please note that the interface of CBitmap is not virtual, so the class is not designed with derivation in mind. Probably, a better design is to derive your CTiledBitmap from CGdiObject and have CBitmap as a private member. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      W 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        An useful question when considering whether you should model your new class as derived from some base class is the following: A CTiledBitmap is a CBitmap? Or put another way: If I change all occurrences of CBitmap with CTiledBitmap in a preexisting program, will the program still work? I guess the answer in your particular case is no. Please note that the interface of CBitmap is not virtual, so the class is not designed with derivation in mind. Probably, a better design is to derive your CTiledBitmap from CGdiObject and have CBitmap as a private member. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        W Offline
        W Offline
        wogerdoger
        wrote on last edited by
        #3

        Thanks 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!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups