Answer Posted / deepak mundhada
enum is a user defined data type . we have to use enum
keyword to specify it.
eg. #include<iostream.h>
class A
{ public:
enum Colour
{ colour_green=0,
colour_peach=0,
colour_white =1,
colour_yellow =2
};
//we cannot have color_green 2 times here
/*enum Colour
{ colour_green=0,
colour_peach=0,
colour_white =1,
colour_yellow =2,
colour_green=3, };
*/
//We cannot have another variable of same type as in enum
Colour
//as below
//int colour_yellow;
//We cannot have colour_white as it already declared in
enum Color
/*enum MyColour
{
colour_red, colour_white };
*/
//We cannot have another Struct or Union of same type as
below
//in the same scope
/*struct Colour
{ int red;
int green; };
*/
void compare(Colour colour1, Colour colour2);
};
void A::compare(A::Colour colour1, A::Colour colour2)
{ if(colour1 == colour2)
{ cout<<"colour1 and colour2 are same\n"; }
}}
int main()
{ A a;
a.compare(A::colour_green,A::colour_peach);
return(0);
}
Output:./a.out
colour1 and colour2 are same
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
How do I use void main?
Can I initialize unions?
Difference between Shallow copy and Deep copy?
By using C language input a date into it and if it is right?
Explain what is the difference between a string and an array?
Can you please explain the difference between exit() and _exit() function?
What is the difference between int main and void main in c?
How can I write a function that takes a format string and a variable number of arguments?
What is a double c?
How reliable are floating-point comparisons?
Why doesn't C support function overloading?
If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above
pierrot's divisor program using c or c++ code
How can you determine the size of an allocated portion of memory?
What is scanf () in c?