473,810 Members | 3,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[March 2005 Preview] overriding virtual function return type differs from 'System::Object ^System::Collec tions::IList::g et_Item(int)'

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\eleme ntWhidbey\Eleme ntList.Mstn.Ben tley.h(97) : error C2553:
'Bentley::Mstn: :Element ^Bentley::Mstn: :ElementList::I tem::get(int)':
overriding virtual function return type differs from 'System::Object
^System::Collec tions::IList::g et_Item(int)'
mscorlib.dll : see declaration of 'System::Collec tions::IList::g et_Item'
Nov 17 '05 #1
6 2742
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
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

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.Collecti ons.CollectionB ase 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.m icrosoft.com> wrote in message
news:4o******** ******@cpmsftng xa10.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
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::Clo ne {
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
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.m icrosoft.com> wrote in message
news:X3******** ******@cpmsftng xa10.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::Clo ne {
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
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**********@b entley.com> wrote in message
news:uv******** *****@TK2MSFTNG P10.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.m icrosoft.com> wrote in message
news:X3******** ******@cpmsftng xa10.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::Clo ne {
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
40008
by: Mike Bartels | last post by:
Hi Everyone! I have two Arrays A and B. Both arrays are byte arrays with 7 bytes each. The contents of array A and B are the same A = {1, 2, 3, 4, 5, 6, 7}; B = {1, 2, 3, 4, 5, 6, 7}; When I do
2
2520
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a pointer or reference to a derived type of the base class's return type. In .NET the overridden virtual function is similar, but an actual parameter of the function can be a derived reference from the base class's reference also. This dichotomy...
8
2219
by: julia_beresford | last post by:
Hi I need to create the following class at runtime: public class MyCollection : CollectionBase { public void Add(MyItem item) { List.Add(item); }
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.