473,385 Members | 1,676 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,385 software developers and data experts.

translate c# to c++

How to translate this to c++

public new Bar this[int nIndex]

{

get{ return (Bar)base[nIndex]; }

}
Nov 17 '05 #1
7 3779
thwei wrote:
How to translate this to c++

public new Bar this[int nIndex]

{

get{ return (Bar)base[nIndex]; }

}


In the new C++ syntax, this translates to (assuming Bar is a ref class):

property Bar^ default [int] {
Bar^ get(int nIndex) { return (Bar^)BaseClassName::default[nIndex]; }
}

In the old syntax, it would be something like this:

__property Bar* get_Item(int nIndex) {
return __try_cast<Bar*>(this->BaseClassName::Item[nIndex]; }
}

In the old syntax, you also need to put this attribute on the containing
__gc class: [System::Reflection::DefaultMember(S"Item")]

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 17 '05 #2
Assuming the class that contains that property derives from a class called
Bar.

[System::Reflection::DefaultMember(S"Item")]
public __gc class Bar
{
public:
__property Bar* get_Item(int index)
{
return NULL;
}
};

public __gc class Foo : public Bar
{
public:
__property Bar* get_Item(int index)
{
return Bar::get_Item(index);
}
};

"thwei" <pawel.stepien(niespamuj)@cubegames.pl> wrote in message
news:cd**********@213.17.234.14...
How to translate this to c++

public new Bar this[int nIndex]

{

get{ return (Bar)base[nIndex]; }

}

Nov 17 '05 #3

Użytkownik "Hasani (remove nospam from address)"
<hb********@n0sp4m.popstick.com> napisał w wiadomości
news:eX**************@tk2msftngp13.phx.gbl...
Assuming the class that contains that property derives from a class called
Bar.

[System::Reflection::DefaultMember(S"Item")]
public __gc class Bar
{
public:
__property Bar* get_Item(int index)
{
return NULL;
}
};

public __gc class Foo : public Bar
{
public:
__property Bar* get_Item(int index)
{
return Bar::get_Item(index);
}
};


Yes, but this one problem:
public __gc class Bar
{
public:
__property Object* get_Item(int index)
{
return NULL;
}
};

public __gc class Foo : public Bar
{
public:
__property Bar* get_Item(int index) //Error C2392 covariant returns types
are not supported in managed types
{
return Bar::get_Item(index);
}
};
Exactly:

public __gc class Foo : public ArrayList
{
public:
__property Bar* get_Item(int index) //Error C2392 covariant returns types
are not supported in managed types
{
return Bar::get_Item(index);
}
};

Nov 17 '05 #4
> In the old syntax, it would be something like this:

__property Bar* get_Item(int nIndex) {
return __try_cast<Bar*>(this->BaseClassName::Item[nIndex]; }
}

In the old syntax, you also need to put this attribute on the containing
__gc class: [System::Reflection::DefaultMember(S"Item")]


Type Item of base class is Object and this generated Error C2392 "covariant
returns types are not supported in managed types"
Nov 17 '05 #5
If you're intention is to derive Foo from ArrayList, you should instead
derive from CollectionBase. The problem is, an array list can store anything
derived from System.Object. In c#, you can use the 'new' keyword to overload
a method, but if your derived class is casted to an IList or an ArrayList,
nothing is to stop the user from calling IList[X] = Foo, or ArrayList[Y] =
Y.
"thwei" <pawel.stepien(niespamuj)@cubegames.pl> wrote in message
news:cd**********@213.17.234.14...

Użytkownik "Hasani (remove nospam from address)"
<hb********@n0sp4m.popstick.com> napisał w wiadomości
news:eX**************@tk2msftngp13.phx.gbl...
Assuming the class that contains that property derives from a class called Bar.

[System::Reflection::DefaultMember(S"Item")]
public __gc class Bar
{
public:
__property Bar* get_Item(int index)
{
return NULL;
}
};

public __gc class Foo : public Bar
{
public:
__property Bar* get_Item(int index)
{
return Bar::get_Item(index);
}
};

Yes, but this one problem:
public __gc class Bar
{
public:
__property Object* get_Item(int index)
{
return NULL;
}
};

public __gc class Foo : public Bar
{
public:
__property Bar* get_Item(int index) //Error C2392 covariant returns

types are not supported in managed types
{
return Bar::get_Item(index);
}
};
Exactly:

public __gc class Foo : public ArrayList
{
public:
__property Bar* get_Item(int index) //Error C2392 covariant returns types are not supported in managed types
{
return Bar::get_Item(index);
}
};

Nov 17 '05 #6
Thanks. Its must derived over CollectionBase and work ok. Thanks again.

Użytkownik "Hasani (remove nospam from address)"
<hb********@n0sp4m.popstick.com> napisał w wiadomości
news:On****************@tk2msftngp13.phx.gbl...
If you're intention is to derive Foo from ArrayList, you should instead
derive from CollectionBase. The problem is, an array list can store anything derived from System.Object. In c#, you can use the 'new' keyword to overload a method, but if your derived class is casted to an IList or an ArrayList,
nothing is to stop the user from calling IList[X] = Foo, or ArrayList[Y] =
Y.

Nov 17 '05 #7
thwei wrote:
Type Item of base class is Object and this generated Error C2392
"covariant returns types are not supported in managed types"


Then the property type needs to be Object. The CLR doesn't support covariant
returns from virtual functions.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 17 '05 #8

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

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
by: shank | last post by:
I'm sure this is a stretch, but is there some kind of component that I could install to translate from English to Spanish on the fly? I have a lot of equipment features and specifications that I...
4
by: Gadrin77 | last post by:
I have data that looks like <Root> <Main Value="Line1|Line2.|Line3|Line4.|Line5"/> </Root> I'm using Translate(@Value, "|.", ",")
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
6
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
1
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
9
bvdet
by: bvdet | last post by:
I have done some more work on a simple class I wrote to calculate a global coordinate in 3D given a local coordinate: ## Basis3D.py Version 1.02 (module macrolib.Basis3D) ## Copyright (c) 2006...
1
by: =?Utf-8?B?R2F1cmF2?= | last post by:
Hi, I am using the Translate() function in one of the .XSLT file to remove the spaces, like this: <xsl:for-each select=".//Illustration"> <xsl:value-of select="translate(./@illusName, ' ',...
3
by: Kenneth McDonald | last post by:
I have the need to occasionally translate a single word programatically. Would anyone have a Python script that would let me do this using Google (or another) translation service? Thanks, Ken
4
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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.