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. Design question for using derived class/ Multiple Base classes

Design question for using derived class/ Multiple Base classes

Scheduled Pinned Locked Moved C / C++ / MFC
questiondesign
31 Posts 5 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.
  • F ForNow

    I'll put another way I thought of the concept derived class(s) as a dervived class uses the base class .. but adds functionality Or Is it just the opposite way of thinking a base has all the functionality but derived class just picks the one it needs

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #18

    ForNow wrote:

    a dervived class uses the base class .. but adds functionality

    A derived class IS the base class.  The derived class can alter and/or add to the functionality of its base class. Again, the class hierarchy shouldn't be designed around the members.  The members are whatever is necessary to implement the functionality of a class. Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    F 1 Reply Last reply
    0
    • M Mark Salsbery

      ForNow wrote:

      a dervived class uses the base class .. but adds functionality

      A derived class IS the base class.  The derived class can alter and/or add to the functionality of its base class. Again, the class hierarchy shouldn't be designed around the members.  The members are whatever is necessary to implement the functionality of a class. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      F Offline
      F Offline
      ForNow
      wrote on last edited by
      #19

      I understand I am going say something to see if I undertand what you mean a typical way of altering functionality would be to declare a method as Virtual that way the derived class can implement Its version of the method Or Since dervied members can have thier version of the Base('s) constructer that would be a way of altering the functionality

      M J 2 Replies Last reply
      0
      • F ForNow

        I understand I am going say something to see if I undertand what you mean a typical way of altering functionality would be to declare a method as Virtual that way the derived class can implement Its version of the method Or Since dervied members can have thier version of the Base('s) constructer that would be a way of altering the functionality

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #20

        ForNow wrote:

        a typical way of altering functionality would be to declare a method as Virtual that way the derived class can implement Its version of the method

        Yes.  That's polymorphism (through inheritance)

        ForNow wrote:

        Since dervied members can have thier version of the Base('s) constructer that would be a way of altering the functionality

        Yes.  Derived class constructors can also both alter and extend the base class constructor implementation, but it's not quite the same as overriding a virtual function.  There's nothing virtual about constructors.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        F 1 Reply Last reply
        0
        • M Mark Salsbery

          ForNow wrote:

          a typical way of altering functionality would be to declare a method as Virtual that way the derived class can implement Its version of the method

          Yes.  That's polymorphism (through inheritance)

          ForNow wrote:

          Since dervied members can have thier version of the Base('s) constructer that would be a way of altering the functionality

          Yes.  Derived class constructors can also both alter and extend the base class constructor implementation, but it's not quite the same as overriding a virtual function.  There's nothing virtual about constructors.

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #21

          Thankx I think I am ready to code.... After being a Dinasour Assembler programmer for 30 years writting procedurel code its hard to change my way thinking

          M 1 Reply Last reply
          0
          • F ForNow

            Thankx I think I am ready to code.... After being a Dinasour Assembler programmer for 30 years writting procedurel code its hard to change my way thinking

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #22

            Have fun!   I coded a few years in assembler and C before C++, but not 30 :) Thinking in terms of classes will be second-nature in no time. Cheers, MArk

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            F 1 Reply Last reply
            0
            • M Mark Salsbery

              Have fun!   I coded a few years in assembler and C before C++, but not 30 :) Thinking in terms of classes will be second-nature in no time. Cheers, MArk

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #23

              Thankx

              1 Reply Last reply
              0
              • L led mike

                1slipperyfish wrote:

                why wouldn't you inherit?

                You are just not following the thread. Your post used classes "Animal" and "Dog" which provide "context" and obviously a Dog "is a" Animal thereby indicating inheritance. However, the original poster used the classes "A" and "B" which provide no context and therefore we cannot distinguish between "is a" or "has a". By the way Mark wants to have lunch with you.

                1 Offline
                1 Offline
                1slipperyfish
                wrote on last edited by
                #24

                i thought that was what was happening and wondered why use A and B?? i am only a learner myself:-O i am on leave all week so any day suits me:-D paul

                if ignorance is bliss then knock the smile off my face!!!

                1 Reply Last reply
                0
                • F ForNow

                  I understand I am going say something to see if I undertand what you mean a typical way of altering functionality would be to declare a method as Virtual that way the derived class can implement Its version of the method Or Since dervied members can have thier version of the Base('s) constructer that would be a way of altering the functionality

                  J Offline
                  J Offline
                  jhwurmbach
                  wrote on last edited by
                  #25

                  Puncuation of some sort would extremely help in getting your ideas across.


                  Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                  George Orwell, "Keep the Aspidistra Flying", Opening words

                  F 1 Reply Last reply
                  0
                  • J jhwurmbach

                    Puncuation of some sort would extremely help in getting your ideas across.


                    Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                    George Orwell, "Keep the Aspidistra Flying", Opening words

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #26

                    ok thankx

                    1 1 Reply Last reply
                    0
                    • F ForNow

                      ok thankx

                      1 Offline
                      1 Offline
                      1slipperyfish
                      wrote on last edited by
                      #27

                      can i add a quetion on the end? i have a base class animalClass.hpp i have a derived Dog class and main in dogObj.cpp and a derived Cat class in catObj.cpp what i wanted to know is should i have animalClass.hpp dogClass.hpp, catClass.hpp, declaring the classes and have a seperate animalObj.cpp for main() to constrol the functions etc? at the moment my animalClass is about fifty lines as are the other animal classes, with my main () about 80 lines thanks in advance paul

                      if ignorance is bliss then knock the smile off my face!!!

                      L F 2 Replies Last reply
                      0
                      • 1 1slipperyfish

                        can i add a quetion on the end? i have a base class animalClass.hpp i have a derived Dog class and main in dogObj.cpp and a derived Cat class in catObj.cpp what i wanted to know is should i have animalClass.hpp dogClass.hpp, catClass.hpp, declaring the classes and have a seperate animalObj.cpp for main() to constrol the functions etc? at the moment my animalClass is about fifty lines as are the other animal classes, with my main () about 80 lines thanks in advance paul

                        if ignorance is bliss then knock the smile off my face!!!

                        L Offline
                        L Offline
                        led mike
                        wrote on last edited by
                        #28

                        1slipperyfish wrote:

                        should i have animalClass.hpp dogClass.hpp, catClass.hpp, declaring the classes and have a seperate animalObj.cpp

                        you need header files (.h, .hpp) if you want to use the classes in other .cpp files so they can be #include < ...> If the class is defined in a cpp file the visibility of it is limited to (not sure) that file maybe.

                        1 1 Reply Last reply
                        0
                        • L led mike

                          1slipperyfish wrote:

                          should i have animalClass.hpp dogClass.hpp, catClass.hpp, declaring the classes and have a seperate animalObj.cpp

                          you need header files (.h, .hpp) if you want to use the classes in other .cpp files so they can be #include < ...> If the class is defined in a cpp file the visibility of it is limited to (not sure) that file maybe.

                          1 Offline
                          1 Offline
                          1slipperyfish
                          wrote on last edited by
                          #29

                          thanks for the reply led mike :D i have rewritten my classes into baseClass.hpp, CatClass.hpp, and DogClass.hpp with farms.cpp initialising the functions and having main() i had a lot of trouble compiling as it kept saying i had already declared my Mammal class in baseClass however if you add [code]#ifndef BASE_CLASS_HPP #define BASE_CLASS_HPP[/code] at the top of baseClass.hpp and [code]#endif[/code] at the bottom it works. you all probably already new that but i've just wasted 2 1/2 hours of my life learning that the hard way:D thanks again paul

                          if ignorance is bliss then knock the smile off my face!!!

                          1 Reply Last reply
                          0
                          • 1 1slipperyfish

                            can i add a quetion on the end? i have a base class animalClass.hpp i have a derived Dog class and main in dogObj.cpp and a derived Cat class in catObj.cpp what i wanted to know is should i have animalClass.hpp dogClass.hpp, catClass.hpp, declaring the classes and have a seperate animalObj.cpp for main() to constrol the functions etc? at the moment my animalClass is about fifty lines as are the other animal classes, with my main () about 80 lines thanks in advance paul

                            if ignorance is bliss then knock the smile off my face!!!

                            F Offline
                            F Offline
                            ForNow
                            wrote on last edited by
                            #30

                            MAybe I shouldn't answer this after all I work as a MainFrame Assembler Dino programmer I think think if you declare it in the code/obj/cpp you just have to qualify the method with Class name e.g. DogClass :: dogmethod saying that this dogmethod is releated to the dogalass Class Trying to get into the future.....

                            1 1 Reply Last reply
                            0
                            • F ForNow

                              MAybe I shouldn't answer this after all I work as a MainFrame Assembler Dino programmer I think think if you declare it in the code/obj/cpp you just have to qualify the method with Class name e.g. DogClass :: dogmethod saying that this dogmethod is releated to the dogalass Class Trying to get into the future.....

                              1 Offline
                              1 Offline
                              1slipperyfish
                              wrote on last edited by
                              #31

                              thanks paul

                              if ignorance is bliss then knock the smile off my face!!!

                              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