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#
  4. about C#

about C#

Scheduled Pinned Locked Moved C#
csharpoop
9 Posts 8 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.
  • K Offline
    K Offline
    king20
    wrote on last edited by
    #1

    Why C# does not support the multiple Inheritance

    K C C P S 5 Replies Last reply
    0
    • K king20

      Why C# does not support the multiple Inheritance

      K Offline
      K Offline
      king20
      wrote on last edited by
      #2

      C# does not having more than one super class tats y we r using interfacing concept to overcome this.

      1 Reply Last reply
      0
      • K king20

        Why C# does not support the multiple Inheritance

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Because it was easier not to, I suspect. You should use interfaces as a poor substitute. Interfaces are cool and useful, but they do not replace multiple inheritence.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        V 1 Reply Last reply
        0
        • K king20

          Why C# does not support the multiple Inheritance

          C Offline
          C Offline
          Chintan Desai
          wrote on last edited by
          #4

          let assume following class class base1{} class base2{} class derive{} :base1,base2 Here if both base class has one common method say Method1().Now,during execution if derived class excess Method1(),then derived class will get confuse :confused: as from which base class i should get Method1(),therefore they were taken out from C# as well as from java.:rose:

          Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

          L T 2 Replies Last reply
          0
          • C Chintan Desai

            let assume following class class base1{} class base2{} class derive{} :base1,base2 Here if both base class has one common method say Method1().Now,during execution if derived class excess Method1(),then derived class will get confuse :confused: as from which base class i should get Method1(),therefore they were taken out from C# as well as from java.:rose:

            Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

            L Offline
            L Offline
            Le centriste
            wrote on last edited by
            #5

            There also the case where 2 base classes inherit from the same base, you then inherit from those 2 classes.

            ----- If atheism is a religion, then not collecting stamps is a hobby. -- Unknown

            1 Reply Last reply
            0
            • C Christian Graus

              Because it was easier not to, I suspect. You should use interfaces as a poor substitute. Interfaces are cool and useful, but they do not replace multiple inheritence.

              Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              I don't know... Stroustrup did it way back in the early 80s. Surely MS in the new millennium should have been able to do it? I think Chintan has the right answer below.

              Cheers, Vıkram.


              After all is said and done, much is said and little is done.

              1 Reply Last reply
              0
              • K king20

                Why C# does not support the multiple Inheritance

                P Offline
                P Offline
                PhilDanger
                wrote on last edited by
                #7

                It is VERY easy to abuse multiple inheritance and end up in "M.I. Hell" -- circular references, inheriting methods from each class that have the same name, destructors being called twice because two bases derive from the same base. All of this can be avoided with careful design, but I think it was a case of protecting the programmer from himself (herself). -Phil PS. I thought I'd save some time/code while programming a strategy/card game in C++ by having the card inherit from the actual unit so it could read it's stats and display it -- since the Card interface had the same accessor names for these stats I had to overload everything in the card in order to call the correct "versions" of these functions, and no time was saved.

                1 Reply Last reply
                0
                • K king20

                  Why C# does not support the multiple Inheritance

                  S Offline
                  S Offline
                  Scott Dorman
                  wrote on last edited by
                  #8

                  From the C# Frequently Asked Questions: http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx[^]

                  ----------------------------- In just two days, tomorrow will be yesterday.

                  1 Reply Last reply
                  0
                  • C Chintan Desai

                    let assume following class class base1{} class base2{} class derive{} :base1,base2 Here if both base class has one common method say Method1().Now,during execution if derived class excess Method1(),then derived class will get confuse :confused: as from which base class i should get Method1(),therefore they were taken out from C# as well as from java.:rose:

                    Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

                    T Offline
                    T Offline
                    Tony Lambert
                    wrote on last edited by
                    #9

                    > Here if both base class has one common method say Method1().Now,during execution if derived class excess Method1(),then derived class will get confuse Not really. :-) This problem has already been solved at a same matter with multiple inheritance interfaces. It could be solved (IMHO with more willing). For example:

                    class base1
                    {
                    void Method()
                    {
                    DoSomethingGood();
                    }
                    }

                    class base2
                    {
                    void Method()
                    {
                    DoSomethingVeryGood();
                    }
                    }

                    class derive : base1, base2
                    {
                    new void base1.Method()
                    {
                    DoSomethingBad();
                    }
                    new void base2.Method()
                    {
                    DoSomethingVeryBad();
                    }
                    }

                    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