473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

covariant return types when overriding

Hi,
Does anyone know what the reason behind not allowing to
use "covariant return types when overriding methods in
derived classes" in C# is?
Also while other OO languages such as Java, don't allow
todo the same, why does C++ allow it and then the C# and
VB.NET don't allow?
I just want to understand the logical reasoning behind
this decision if there is one.

TIA
Srinivasa Sankar Nemani
Nov 15 '05 #1
3 1527
Hello Sankar,
does C++ allow it and then the C# and VB.NET don't
allow? I just want to understand the logical
reasoning behind this decision if there is one.


I've wondered about this myself, but have not come to any
conclusions. This question has been asked before but I haven't seen an
'offical' answer yet. You can check the 'ask a language designer' page
on gotdotnet.com. The question was posted there over a year ago....
still no answer, but it might come someday.

http://www.gotdotnet.com/team/csharp...lumns/ask.aspx

Later,
Len
Nov 15 '05 #2
Sankar Nemani <sn*****@lumedx.com> wrote:
Does anyone know what the reason behind not allowing to
use "covariant return types when overriding methods in
derived classes" in C# is?


I don't know, but I'd strongly suspect that it'll go away when generics
are introduced to C#, just as it's going away in Java in 1.5 as a
corollary of adding generics there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3
Sankar,
I've wondered the same thing myself. The last time someone asked this, a
link was posted about why covariant return types don't work, but I don't
have that link handy.

If you want 'covariant return types' in .NET today, you can use Eiffel.

http://www.eiffel.com/

Of course only Eiffel code can make use of them, I'm not sure what happens
when you attempt to interop with normal .NET code.

I'm not sure if future versions of C# or VB.NET will include it, nor how
much of the CLR needs to support it for a language to fully support it.

Hope this helps
Jay

"Sankar Nemani" <sn*****@lumedx.com> wrote in message
news:05****************************@phx.gbl...
Hi,
Does anyone know what the reason behind not allowing to
use "covariant return types when overriding methods in
derived classes" in C# is?
Also while other OO languages such as Java, don't allow
todo the same, why does C++ allow it and then the C# and
VB.NET don't allow?
I just want to understand the logical reasoning behind
this decision if there is one.

TIA
Srinivasa Sankar Nemani

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Stefan Slapeta | last post by:
Hi, this code does not compile in C#: class base_class {} class derived_class : base_class {} class A { public virtual base_class f()
13
by: Stephen Walch | last post by:
Error C2392 is hitting me hard! I have a managed C++ library that implements a bunch of fixed interfaces. For example, one interface is: public abstract interface IDbCommand { public...
4
by: Rob Grainger | last post by:
Hi, When compiling the following code under VC .NET, template <typename T> class IBaseCollection { public: virtual T Get() const = 0; };
16
by: Bob Hairgrove | last post by:
Consider the classic clone() function: class A { public: virtual ~A() {} virtual A* clone() const = 0; }; class B : public A { public:
6
by: miked | last post by:
Why are there still no covariant return types? All searches reveal no workarounds accept for using an interface which is a real pain. I wind up missing this capability almost every time I...
8
by: Alex Vinokur | last post by:
Here is a code from http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8 -------------------------------------- class Shape { public: virtual ~Shape() { } // A...
3
by: kikazaru | last post by:
Is it possible to return covariant types for virtual methods inherited from a base class using virtual inheritance? I've constructed an example below, which has the following structure: Shape...
2
by: Sebastian Schucht | last post by:
Hi, I have a templateclass with virtual member-functions, so i can't create instances ... but for returning the result i would like use one. So i replaced the A<TTypefrom the baseclass with the...
9
by: Rahul | last post by:
Hi Everyone, I was trying to implement covariant return types and i get a compilation error, class BB : public AA { }; class A
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.