inheritance issue
-
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
-
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
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?"
-
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?"
-
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
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
-
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
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
-
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
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 ofabc_voucher
s, you can only interpret the contents of the list asabc_voucher
objects. /raviThis is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
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
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?"
-
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?"