enum initializing

how can i initialize double or char or string to enum?

1
2
3
4
5
 enum players{
player_1=/*'a'*/,
player_2=2.3,
player_3="/*string*/,
}; 
I think you may be misunderstanding what an enumeration is for. What are you trying to do?
can you explain to me what it is for?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
enum e_usflcnst{
CATLIFE_FACTOR=7.6 //enumerator value for catlife_factor is not an integer
                                   // this is what im tryin to do
};

int main()
{
	int age;
	cout << "Enter your age: ";
	cin >> age;
age /=CATLIFE_FACTOR;
	if(age==0)
{
return EXIT_SUCCESS;
}
else
	{

		cout << "If you were cat, you would be " << age << endl;
}}
Last edited on
enumeration is always contains integral constants. And it should not be used to set constants.

For your needs, you should use normal constant:const double CATLIFE_FACTOR = 7.6;

You can even wrap it in namespace:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
namespace useful_constants
{
    const double CATLIFE_FACTOR = 7.6;
    const std::string OUR_PLANET = "Earth";
}

namespace uc = useful_constants;

int main()
{
    std::cout << uc::CATLIFE_FACTOR << '\n';
    using namespace uc;
    std::cout << OUR_PLANET;
}

Last edited on
is that still an enum?
No it is not an enum. You cannot use enum the way you want because they are not suitable for this task.
Topic archived. No new replies allowed.