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
Explain what is the best way to comment out a section of code that contains comments?
How arrays can be passed to a user defined function
How can you read a directory in a C program?
How will you delete a node in DLL?
Tell me the use of bit field in c language?
How can you convert integers to binary or hexadecimal?
I need previous papers of CSC.......plz help out by posting them.......
For what purpose null pointer used?
Explain what does the function toupper() do?
What is the best way of making my program efficient?
How does struct work in c?
What is void main () in c?
Differentiate between declaring a variable and defining a variable?
Write a code to remove duplicates in a string.
What do you mean by recursion in c?