473,326 Members | 2,126 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,326 software developers and data experts.

Default accessor in MC++

I have a CS class I wish to write in MC++:

public class UnitsCollection : ArrayList
{
new public Units this[int index]
{
get { return (Units) base[index]; }
set { base[index] = value; }
}
}

Would the MC++ class below be equivalent?

[DefaultMember("Item")]
public __gc class UnitsCollection : public ArrayList
{
public:
__property Units* get_Item(int index) {
return (Units*)__super[index];
}
__property void set_Item(Units* u) {
__super::Add(u);
}
};

--
Daniel
Nov 17 '05 #1
3 2215
Daniel Lidström wrote:
I have a CS class I wish to write in MC++:

public class UnitsCollection : ArrayList
{
new public Units this[int index]
{
get { return (Units) base[index]; }
set { base[index] = value; }
}
}

Would the MC++ class below be equivalent?

[DefaultMember("Item")]
public __gc class UnitsCollection : public ArrayList
{
public:
__property Units* get_Item(int index) {
return (Units*)__super[index];
}
__property void set_Item(Units* u) {
__super::Add(u);
}
};


MC++ doesn't support C#'s indexer syntax.. instead of
'collection[index]' you must write 'collection->Item[index]', and so on.
In this case you need '__super::Item[index]'. Also, since get_Item takes
an index, set_Item should also.

Try changing the property accessors as follows:

__property Units* get_Item(int index) {
return (Units*)__super::Item[index];
}
__property void set_Item(int index, Units* u) {
__super::Item[index] = u;
}

Jesse
Nov 17 '05 #2
On Thu, 27 May 2004 21:48:00 -0700, Jesse McGrew wrote:
Daniel Lidström wrote:
I have a CS class I wish to write in MC++:

public class UnitsCollection : ArrayList
{
new public Units this[int index]
{
get { return (Units) base[index]; }
set { base[index] = value; }
}
}

Would the MC++ class below be equivalent?

[DefaultMember("Item")]
public __gc class UnitsCollection : public ArrayList
{
public:
__property Units* get_Item(int index) {
return (Units*)__super[index];
}
__property void set_Item(Units* u) {
__super::Add(u);
}
};


MC++ doesn't support C#'s indexer syntax.. instead of
'collection[index]' you must write 'collection->Item[index]', and so on.
In this case you need '__super::Item[index]'. Also, since get_Item takes
an index, set_Item should also.

Try changing the property accessors as follows:

__property Units* get_Item(int index) {
return (Units*)__super::Item[index];
}
__property void set_Item(int index, Units* u) {
__super::Item[index] = u;
}


When I try this I get the following compile error:
error C2392: 'LX::Units __gc *LX::UnitsCollection::get_Item(int)' :
covariant returns types are not supported in managed types

I think it means Item is already in the baseclass. Would it be a solution
to change to

__property Units* UnitsCollection::get_Index(int index) {
return (Units*)__super::Item[index];
}
__property void UnitsCollection::set_Index(int index, Units* u) {
__super::Item[index] = u;
}

And put [System::Reflection::DefaultMemberAttribute("Index" )] attribute on
the UnitsCollection class?

Is this how I use the default accessor? It compiles anyhow.

UnitsCollection* units = new UnitsCollection;
Units* unit = new Units();
units->Index[0] = unit;

--
Daniel
Nov 17 '05 #3
Daniel Lidström wrote:
When I try this I get the following compile error:
error C2392: 'LX::Units __gc *LX::UnitsCollection::get_Item(int)' :
covariant returns types are not supported in managed types

I think it means Item is already in the baseclass. Would it be a solution
to change to

__property Units* UnitsCollection::get_Index(int index) {
return (Units*)__super::Item[index];
}
__property void UnitsCollection::set_Index(int index, Units* u) {
__super::Item[index] = u;
}

And put [System::Reflection::DefaultMemberAttribute("Index" )] attribute on
the UnitsCollection class?
Yes.

The compiler thinks you're trying to override ArrayList's get_Item
method (which is virtual) instead of replacing it, since yours has the
same parameters, but the return type differs so you get an error. In C#,
you could use the 'new' keyword to hide the inherited member instead of
overriding it, but I don't think MC++ has an equivalent.
Is this how I use the default accessor? It compiles anyhow.

UnitsCollection* units = new UnitsCollection;
Units* unit = new Units();
units->Index[0] = unit;


Yes.

In MC++ the default accessor is no different from any other indexed
property. The [DefaultMember] attribute only affects other languages
such as C#.

Jesse
Nov 17 '05 #4

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

Similar topics

3
by: Mike Irwin | last post by:
I'm having a little difficulty with the set accessor. I'm working on a template-based site design and trying to use the set accessor to set the document's title. The problem is that it's not...
3
by: Eric Eggermann | last post by:
Hello, I'm trying to use xsd.exe to create a schema from my exe and I get an error saying that my collection class does not implement a default accessor which it must since it inherits from...
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
2
by: Justin Drerup | last post by:
I'm tryng to return a custom object that contains a collection of MembershipUsers through a web service however I receive the following error when trying to return the object through a web method:...
2
by: Lou | last post by:
I getthis error when trying to serialize a collection class. Dim Serialize As XmlSerializer = New XmlSerializer(GetType(cButtons)) "You must implement a default accessor on...
1
by: A. Nonymous | last post by:
First off, I would like to state that I'm using VS.2003 / .NET Framework 1.1 and the MC++ that comes with it. I am stuck with this IDE for the time being as I am supporting some older platforms. ...
5
by: mc | last post by:
Hello, I'm trying to create a class (A) with a default constructor friend to another one (B) as follows: class A { public: A(int a); ~A();
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.