how to create an enum type object which is inside a class

Aug 20, 2008 at 12:02pm
hi
how to create an enum type object which is inside a class.The enum object is created ouside the class.
Last edited on Aug 20, 2008 at 12:06pm
Aug 20, 2008 at 12:40pm
Enums aren't objects. They are... Well, enumerations.
Is this what you're looking for?
1
2
3
4
5
6
7
8
9
10
class A{
    //...
    enum N{
        ONE,
        TWO,
        THREE,
        FOUR,
    };
    //...
};
Aug 20, 2008 at 2:07pm
Is thsi what you are after?

1
2
3
4
5
6
7
8
9
10
11
enum colour{red, blue, green};      //Declare the enumeration

class a
{
    colour theColour;      //Declare a variable of the type in the class;
    ...
}

a myInstance; //declare an instance of class

a.colour = red;   //set varaible to one of the enumerations; 
Aug 20, 2008 at 3:53pm
how to create an enum type object which is inside a class.The enum object is created ouside the class.


helios & Faldrax Gave you some explanations.

I understood it like the enum is defined in the class and you want an enum variable outside the class.

1
2
3
4
5
6
7
8
class myClass{
//...
public:
   enum myEnum{ One, Two, Three };
   //...
};
//...
myClass::myEnum enumVar = myClass::One;


I think now we have all the possible answers :D
Last edited on Aug 20, 2008 at 3:54pm
Aug 21, 2008 at 10:07am
Thanks helios & Faldrax.

I understood it like the enum is defined in the class and you want an enum variable outside the class.

Exactly

Thank u Mitsakos.

How do i mention enumVar in the declaration myClass::myEnum enumVar ,if enumVar is not an object(should i mention it as a Type).
Last edited on Aug 21, 2008 at 10:10am
Aug 21, 2008 at 10:35am
How do i mention enumVar in the declaration myClass::myEnum enumVar ,if enumVar is not an object(should i mention it as a Type).

I'm sorry, I don't understand what you mean.
Aug 21, 2008 at 11:07am
We mention(ie. we call the ,we refer the, we say the) the instance of a class as object, How to mention(ie. refer ) the instance of a enum.
Last edited on Aug 21, 2008 at 11:51am
Aug 21, 2008 at 12:02pm
I don't know... I think enum type, at least that's how I call it :D
Aug 21, 2008 at 8:04pm
The type name is "enumeration type" and objects of it are called... "object of enumeration type".
Aug 22, 2008 at 10:40am
Hi,
I am Rammohan from Bangalore and working as a Technical lead in big IT firm .
Solution for your answer is follows:


You can do write Enumaraters object in C++ class is follows:
1. class ArticleCollection : public IEnumerable
2. {
3. ...
4. public:
5. IEnumerator* GetEnumerator()
6. {
7. return dynamic_cast<IEnumerator*>(
8. new ArticleEnumerator(this));
9. }
10.
11. public:
12. __gc class ArticleEnumerator : public IEnumerator
13. {
14. };
15. ...

____________________
Regards,
Rammohan Alampally,
rammohan@india.com
Technical Lead,
Bangalore, India.
[COLOR="Red"]www.FindSyntax.com -> Worlds first Web based Windows O/S is a Brain Chaild of Rammohan[/COLOR]
Aug 22, 2008 at 1:34pm
Thank u Mitsakos

Did any one understand the code of Mr.FindSyntax,if yes,please explain.
Aug 22, 2008 at 2:20pm
He has confused your request for information on enum, or 'enumerated types' with 'Enumerators'.

The purpose of enumerators is to 'enumerate' a list (IE to perform some action on each member of the list in turn) using the for each syntax.
I belive this may be specific to MS .Net extensions to C++. The code he has given is the older 'managed extensions' (VC++ 2003) rather than the newer C++/CLI (VC++ 2005 or 2008).


Aug 28, 2008 at 5:50am
when we declare enum wt size it takes.means wts memory it occupy.
Topic archived. No new replies allowed.