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

hi
how to create an enum type object which is inside a class.The enum object is created ouside the class.
Last edited on
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,
    };
    //...
};
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; 
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
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
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.
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
I don't know... I think enum type, at least that's how I call it :D
The type name is "enumeration type" and objects of it are called... "object of enumeration type".
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]
Thank u Mitsakos

Did any one understand the code of Mr.FindSyntax,if yes,please explain.
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).


when we declare enum wt size it takes.means wts memory it occupy.
Topic archived. No new replies allowed.