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

How Do I create a MCPP Property which returns an enum? - My Class will not compile, can you fix it?

I am trying to create a property which returns an enum.
The following class does not work, can someone fix it?
I am using VS2003 C++

public __gc class Drive
{
public:
Drive(){}
__property DriveType get_DriveType()
{
return _DriveType;
}
// This is the enum type
__value enum DriveType
{
CDROM, FIXED, REMOVABLE
};

private:
DriveType _DriveType;
};

Thanks
Russell Mangel
Las Vegas, NV
Nov 17 '05 #1
2 1216
Russell Mangel wrote:
I am trying to create a property which returns an enum.
The following class does not work, can someone fix it?
I am using VS2003 C++


Russell,

I believe the problem is caused by having a property with the same name
as the enum. (Both called DriveType)

The two possibilities I can see are:

1. rename the Enum (or the property)

public __gc class Drive
{
public:
Drive(){}
__property int get_DriveType()
{
return 2;// _DriveType;
}
__value enum DriveType2
{
CDROM, FIXED, REMOVABLE
};

private:
DriveType2 _DriveType;
};
2. Declare the enum outside the class and use the scope operator:

__value enum DriveType
{
CDROM, FIXED, REMOVABLE
};
public __gc class Drive
{
public:
Drive(){}
__property int get_DriveType()
{
return 2;// _DriveType;
}

private:
::DriveType _DriveType;
};
hth
--
Ben
http://bschwehn.de
Nov 17 '05 #2
Hi Russell,
I am trying to create a property which returns an enum.
The following class does not work, can someone fix it?
I am using VS2003 C++

public __gc class Drive
{
public:
Drive(){}
__property DriveType get_DriveType()
{
return _DriveType;
}
// This is the enum type
__value enum DriveType
{
CDROM, FIXED, REMOVABLE
};

private:
DriveType _DriveType;
};

Thanks
Russell Mangel
Las Vegas, NV


There are two problems with your code:
The first one is that the enum is defined after the property, so you need to
move it above it so that it can be seen at that point by the compiler.
The second is that the property getter will end up generating a property
that has the same name as the type, so that Drive::DriveType will be
ambiguous (it would mean both the type and the property). This can be easily
fixed by renaming either one. Also, you'll want to make the enum definition
public, as well.

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #3

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

Similar topics

3
by: gry | last post by:
I often find myself wanting an instance attribute that can take on only a few fixed symbolic values. (This is less functionality than an enum, since there are no *numbers* associated with the...
20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
5
by: Alan Cobb | last post by:
Hi, In the managed C++ class below I get compile warning C4677 from VS2003. "signature of non-private function contains assembly private type", even though the managed enum is public. I have...
2
by: Russell Mangel | last post by:
I am trying to create a property which returns an enum. The following class does not work, can someone fix it? I am using VS2003 C++ public __gc class Drive { public: Drive(){} __property...
3
by: Boni | last post by:
Dear All, we have a big project with C# and MCPP mixed assemblies. Is MCPP still supported in VS2005? Do we have to change something in MCPP? With best regards, Boni
13
by: docschnipp | last post by:
Hi, I have a bunch of object derived from the same base class. They all share the same constructor with some parameters. Now, instead of using a large switch() statement where I call every...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.