By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

[March 2005 Preview] overriding virtual function return type differs from 'System::Object ^System::Collections::IList::get_Item(int)'

P: n/a
I'm trying to use the VS 2005 March Tech Preview and am trying to adjust
some MC++ to the new C++/CLI syntax. I got a little hung up when I
encountered the below error. Certainly my 'Bentley::Mstn::Element' type
derives ultimately from System::Object. It is a ref class. And upcasting is
always implicit right? So I don't understand why I'm getting this error.
It's happening on my get method:

property Bentley::Mstn::Element^ Item[]
{
Bentley::Mstn::Element^ get(int index);
void set (int index, Bentley::Mstn::Element^ value);
}

And here is the error

C:\mycode\elementWhidbey\ElementList.Mstn.Bentley. h(97) : error C2553:
'Bentley::Mstn::Element ^Bentley::Mstn::ElementList::Item::get(int)':
overriding virtual function return type differs from 'System::Object
^System::Collections::IList::get_Item(int)'
mscorlib.dll : see declaration of 'System::Collections::IList::get_Item'
Nov 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Bern,

Currently we don't support the VS 2005 Preview, however I have consulted
your problem to the dev team, I will reply you if I got any result.
Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 17 '05 #2

P: n/a
Hi Bern,

One dev team member gave the following answer to your question:
"The compiler in the Tech Preview does not support covariant returns for
member functions (or properties) of managed classes. It is a restriction
imposed by the CLI, so I donĄ¯t think C++/CLI or the Whidbey compiler will
allow them."
Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 17 '05 #3

P: n/a

That deserves further explanation. The code snippet I gave is the textbook
way to create a type-safe collection pre-Whidbey is it not? You derive from
System.Collections.CollectionBase and then, among other things, you can
override get_Item(int index) and do a cast of List->item[index] from
System.Object * to the type that you're making a collection of. This is
straight out of the documentation.

I realize that as of Whidbey there are superior ways to do type-safe
collections, but are you saying that code written to follow the past
recommended practice for creating type-safe collections will not even
compile in Whidbey? Is CollectionBase being removed from the framework
then? There doesn't seem to be much point in keeping it if the compilers
won't let you use it as intended.

Bern McCarty
Bentley Systems, Inc.
"Gary Chang" <v-******@online.microsoft.com> wrote in message
news:4o**************@cpmsftngxa10.phx.gbl...
Hi Bern,

One dev team member gave the following answer to your question:
"The compiler in the Tech Preview does not support covariant returns for
member functions (or properties) of managed classes. It is a restriction
imposed by the CLI, so I donĄ¯t think C++/CLI or the Whidbey compiler will
allow them."
Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights. --------------------

Nov 17 '05 #4

P: n/a
Hi Bern,

Our dev team has provided an example in the new syntax of doing the
explicit interface implementation which is how you write a typesafe
collection in generic-less CLR:

ref class R : ICloneable {
int X;
virtual Object^ C() = ICloneable::Clone {
return this->Clone();
}

public:
R() : X(0) {}
R(int x) : X(x) {}

virtual R^ Clone() new {
R^ r = gcnew R;
r->X = this->X;
return r;
}
};
Wish it helps!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 17 '05 #5

P: n/a
Thanks Gary. I'll have to study the C++/CLI draft to try to understand that
code. Meanwhile, could you provide an example of how to do the same thing
using /clr:oldsyntax ?

Bern McCarty
Bentley Systems, Inc.
"Gary Chang" <v-******@online.microsoft.com> wrote in message
news:X3**************@cpmsftngxa10.phx.gbl...
Hi Bern,

Our dev team has provided an example in the new syntax of doing the
explicit interface implementation which is how you write a typesafe
collection in generic-less CLR:

ref class R : ICloneable {
int X;
virtual Object^ C() = ICloneable::Clone {
return this->Clone();
}

public:
R() : X(0) {}
R(int x) : X(x) {}

virtual R^ Clone() new {
R^ r = gcnew R;
r->X = this->X;
return r;
}
};
Wish it helps!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights. --------------------

Nov 17 '05 #6

P: n/a
Hi Bern,

That isn't possible in a direct way since the 7.0/7.1 syntax does not
support explicit interface implementation.

Ronald Laeremans
Visual C++ team

"Bern McCarty" <be**********@bentley.com> wrote in message
news:uv*************@TK2MSFTNGP10.phx.gbl...
Thanks Gary. I'll have to study the C++/CLI draft to try to understand
that
code. Meanwhile, could you provide an example of how to do the same thing
using /clr:oldsyntax ?

Bern McCarty
Bentley Systems, Inc.
"Gary Chang" <v-******@online.microsoft.com> wrote in message
news:X3**************@cpmsftngxa10.phx.gbl...
Hi Bern,

Our dev team has provided an example in the new syntax of doing the
explicit interface implementation which is how you write a typesafe
collection in generic-less CLR:

ref class R : ICloneable {
int X;
virtual Object^ C() = ICloneable::Clone {
return this->Clone();
}

public:
R() : X(0) {}
R(int x) : X(x) {}

virtual R^ Clone() new {
R^ r = gcnew R;
r->X = this->X;
return r;
}
};
Wish it helps!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no

rights.
--------------------


Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.