Click here to Skip to main content
15,888,908 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: cast to c++ interface from C# Pin
Natty Gur16-Apr-03 20:11
Natty Gur16-Apr-03 20:11 
GeneralUnmanaged code to call managed code Pin
onyxbird10-Apr-03 9:43
onyxbird10-Apr-03 9:43 
GeneralRe: Unmanaged code to call managed code Pin
Paul Selormey10-Apr-03 18:03
Paul Selormey10-Apr-03 18:03 
GeneralC2682: cannot use __try_cast to convert from 'gcroot<T>' Pin
Paul Selormey31-Mar-03 20:40
Paul Selormey31-Mar-03 20:40 
GeneralRe: C2682: cannot use __try_cast to convert from 'gcroot<T>' Pin
Paul Selormey1-Apr-03 0:51
Paul Selormey1-Apr-03 0:51 
GeneralMixing ATL and MC++ Pin
Heath Stewart26-Mar-03 3:17
protectorHeath Stewart26-Mar-03 3:17 
GeneralRe: Mixing ATL and MC++ Pin
Paul Selormey26-Mar-03 13:29
Paul Selormey26-Mar-03 13:29 
GeneralCovariant return types Pin
VizOne24-Mar-03 22:52
VizOne24-Mar-03 22:52 
Hi!

I'd like to implement my own Collection that derives from Collection Base. I want the Item-property to have the proper return type instead of Object*. In C# it is easy to implement a Covariant return type:

<br />
class MyData<br />
{<br />
    public int Value<br />
    {<br />
        get { return 5; }<br />
    }<br />
};<br />
<br />
class MyCollection : CollectionBase<br />
{<br />
    public MyData this[int index] // override indexer from IList<br />
    {<br />
        get{ return (MyData)List[index]; }<br />
        set{ List[index] = value; }<br />
    }<br />
};<br />


In VC++.net, however it does not seem to be possible, as covariant return types are not allowed - at least in VC++.net:

<br />
__gc class MyData<br />
{<br />
    __property int get_Value()<br />
    {<br />
        return 5;<br />
    }<br />
};<br />
<br />
[Reflection::DefaultMember(S"Item")] // let Item be the indexer<br />
__gc class MyCollection<br />
: public System::Collections::CollectionBase<br />
{<br />
    __property MyData * get_Item(int in_index) // C2392- Error!<br />
    {<br />
        return static_cast<MyData*>(List->Item[in_index]);<br />
    }<br />
};<br />



Is there any attribute or another way to achieve what I'd like to do?
I am using VS.net 2002. Might this feature be available in vs.net 2003?

Thanks in advance!

- Andre
GeneralRe: Covariant return types Pin
Paul Selormey26-Mar-03 0:41
Paul Selormey26-Mar-03 0:41 
GeneralRe: Covariant return types Pin
VizOne26-Mar-03 0:53
VizOne26-Mar-03 0:53 
GeneralRe: Covariant return types Pin
Paul Selormey26-Mar-03 1:12
Paul Selormey26-Mar-03 1:12 
GeneralRe: Covariant return types Pin
VizOne26-Mar-03 8:35
VizOne26-Mar-03 8:35 
GeneralRe: Covariant return types Pin
Paul Selormey26-Mar-03 13:22
Paul Selormey26-Mar-03 13:22 
GeneralRe: Covariant return types Pin
Daniel Turini14-Apr-03 0:52
Daniel Turini14-Apr-03 0:52 
GeneralRe: Covariant return types Pin
Paul Selormey26-Mar-03 19:05
Paul Selormey26-Mar-03 19:05 
GeneralSocket function error Pin
TeraCoder24-Mar-03 14:23
TeraCoder24-Mar-03 14:23 
GeneralRe: Socket function error Pin
Paul Selormey24-Mar-03 17:33
Paul Selormey24-Mar-03 17:33 
GeneralForm within Form ... Pin
Maximilien21-Mar-03 11:59
Maximilien21-Mar-03 11:59 
GeneralRe: Form within Form ... Pin
Paul Selormey24-Mar-03 17:30
Paul Selormey24-Mar-03 17:30 
GeneralDisplaying a dialog from a DLL Pin
Squatch618-Mar-03 17:04
Squatch618-Mar-03 17:04 
GeneralRe: Displaying a dialog from a DLL Pin
Paul Selormey18-Mar-03 18:21
Paul Selormey18-Mar-03 18:21 
GeneralRe: Displaying a dialog from a DLL Pin
John R. Shaw29-Apr-03 19:13
John R. Shaw29-Apr-03 19:13 
GeneralManaged and Unmanaged Pin
Nicholas Naddaf18-Mar-03 7:32
Nicholas Naddaf18-Mar-03 7:32 
GeneralRe: Managed and Unmanaged Pin
Nish Nishant18-Mar-03 7:36
sitebuilderNish Nishant18-Mar-03 7:36 
GeneralRe: Managed and Unmanaged Pin
Nicholas Naddaf18-Mar-03 7:56
Nicholas Naddaf18-Mar-03 7:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.