Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

Default accessor in MC++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel =?iso-8859-1?Q?Lidstr=F6m?= - 27 May 2004 10:36 GMT
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);
 }
};

Signature

Daniel

Jesse McGrew - 28 May 2004 05:48 GMT
Daniel Lidström wrote:
> I have a CS class I wish to write in MC++:
>
[quoted text clipped - 20 lines]
>   }
> };

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
Daniel =?iso-8859-1?Q?Lidstr=F6m?= - 28 May 2004 08:30 GMT
> Daniel Lidström wrote:
>> I have a CS class I wish to write in MC++:
[quoted text clipped - 35 lines]
>      __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;

Signature

Daniel

Jesse McGrew - 28 May 2004 19:37 GMT
Daniel Lidström wrote:
> When I try this I get the following compile error:
> error C2392: 'LX::Units __gc *LX::UnitsCollection::get_Item(int)' :
[quoted text clipped - 12 lines]
> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.