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. inheritance issue

inheritance issue

Scheduled Pinned Locked Moved C#
helpoopquestion
8 Posts 4 Posters 2 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.
  • T Offline
    T Offline
    Tauseef A
    wrote on last edited by
    #1

    hi guys i have a class named abc_voucher and another class derived from abc_voucher named def_voucher, but in my application i have a function and its return type is generic list of abc_voucher and i am returning from this function the generic list of class def_voucher which is derived from abc_voucher , but it gives an comlite time error ,, though my return object is derived from the type which i am returning in function's signature , why is that ? thanks in advance

    hello

    M S 2 Replies Last reply
    0
    • T Tauseef A

      hi guys i have a class named abc_voucher and another class derived from abc_voucher named def_voucher, but in my application i have a function and its return type is generic list of abc_voucher and i am returning from this function the generic list of class def_voucher which is derived from abc_voucher , but it gives an comlite time error ,, though my return object is derived from the type which i am returning in function's signature , why is that ? thanks in advance

      hello

      M Offline
      M Offline
      Mustafa Ismail Mustafa
      wrote on last edited by
      #2

      ghumman63 wrote:

      comlite time error

      What is this??

      ghumman63 wrote:

      but in my application i have a function and its return type is generic list of abc_voucher and i am returning from this function the generic list of class def_voucher which is derived from abc_voucher , but it gives an comlite time error

      Are you extracting the def_voucher list from the list that you retrieved that has the abc_voucher list? Is that what you're doing?

      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

      T 1 Reply Last reply
      0
      • M Mustafa Ismail Mustafa

        ghumman63 wrote:

        comlite time error

        What is this??

        ghumman63 wrote:

        but in my application i have a function and its return type is generic list of abc_voucher and i am returning from this function the generic list of class def_voucher which is derived from abc_voucher , but it gives an comlite time error

        Are you extracting the def_voucher list from the list that you retrieved that has the abc_voucher list? Is that what you're doing?

        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

        T Offline
        T Offline
        Tauseef A
        wrote on last edited by
        #3

        no i am not extracting def_voucher is derived from abc_voucher , but it gives compile time error public function abc as list(of abc_voucher) dim list as new list(of def)voucher) ' function body ' return list end function

        hello

        1 Reply Last reply
        0
        • T Tauseef A

          hi guys i have a class named abc_voucher and another class derived from abc_voucher named def_voucher, but in my application i have a function and its return type is generic list of abc_voucher and i am returning from this function the generic list of class def_voucher which is derived from abc_voucher , but it gives an comlite time error ,, though my return object is derived from the type which i am returning in function's signature , why is that ? thanks in advance

          hello

          S Offline
          S Offline
          sreejith ss nair
          wrote on last edited by
          #4

          Hi, Sorry to tell you that, i am not getting what you are trying to achive appart from some class relation. namespace CS { class Program { static void Main(string[] args) { B Obj = new B(); List _list =Obj.GetList(); } } /// /// base /// class A { protected int Age=0; public A() { } public A(int age) { this.Age = age; } } /// /// derived /// class B : A { public List GetList() { List GList = new List(); GList.Add(new A(21)); GList.Add(new A(22)); GList.Add(new A(23)); return GList; } } } Presumably, the above lines of code will give an idea on the route map.

          If the post/article served your purpose then, please assist me in keeping it up by donating a small amount of money to my Paypal account. Email: sreejithssnair@hotmail.com

          T 1 Reply Last reply
          0
          • S sreejith ss nair

            Hi, Sorry to tell you that, i am not getting what you are trying to achive appart from some class relation. namespace CS { class Program { static void Main(string[] args) { B Obj = new B(); List _list =Obj.GetList(); } } /// /// base /// class A { protected int Age=0; public A() { } public A(int age) { this.Age = age; } } /// /// derived /// class B : A { public List GetList() { List GList = new List(); GList.Add(new A(21)); GList.Add(new A(22)); GList.Add(new A(23)); return GList; } } } Presumably, the above lines of code will give an idea on the route map.

            If the post/article served your purpose then, please assist me in keeping it up by donating a small amount of money to my Paypal account. Email: sreejithssnair@hotmail.com

            T Offline
            T Offline
            Tauseef A
            wrote on last edited by
            #5

            leave it assume i want to to the following def_voucher is derived from abc_voucher but it says that cant convert type of abc_voucher t0 def_coucher ,, why ? though def_voucher is derived from abc_voucher .. public function abc as abc_voucher dim vc as new def_voucher (); return vc; end function -- modified at 4:06 Thursday 29th November, 2007

            hello

            R M 2 Replies Last reply
            0
            • T Tauseef A

              leave it assume i want to to the following def_voucher is derived from abc_voucher but it says that cant convert type of abc_voucher t0 def_coucher ,, why ? though def_voucher is derived from abc_voucher .. public function abc as abc_voucher dim vc as new def_voucher (); return vc; end function -- modified at 4:06 Thursday 29th November, 2007

              hello

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #6

              ghumman63 wrote:

              but it says that cant convert type of abc_voucher t0 def_coucher

              That's because you can't upcast, only downcast. So while you can add a def_voucher object to a collection of abc_vouchers, you can only interpret the contents of the list as abc_voucher objects. /ravi

              This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

              1 Reply Last reply
              0
              • T Tauseef A

                leave it assume i want to to the following def_voucher is derived from abc_voucher but it says that cant convert type of abc_voucher t0 def_coucher ,, why ? though def_voucher is derived from abc_voucher .. public function abc as abc_voucher dim vc as new def_voucher (); return vc; end function -- modified at 4:06 Thursday 29th November, 2007

                hello

                M Offline
                M Offline
                Mustafa Ismail Mustafa
                wrote on last edited by
                #7

                That's because inheritance is a form of specialization of abstractions. Student is a special form of Person etc. You cannot specialize something general, but you can generalize something specialized. This is analogous to saying "Every Student is a Person" [Generalization] But you cannot say that "Every Person is a Student"

                "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

                T 1 Reply Last reply
                0
                • M Mustafa Ismail Mustafa

                  That's because inheritance is a form of specialization of abstractions. Student is a special form of Person etc. You cannot specialize something general, but you can generalize something specialized. This is analogous to saying "Every Student is a Person" [Generalization] But you cannot say that "Every Person is a Student"

                  "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"

                  T Offline
                  T Offline
                  Tauseef A
                  wrote on last edited by
                  #8

                  i am sorry i cant get, when i do the following function abc as ilist dim xyz as new list(of def_coucher) return xyx end function here it works fine , why ? the same i am doing in my previous case .. thanks in advance

                  hello

                  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