Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

How can I pass a variable name to an enum to return a value?

$
0
0

In c++, is it possible to pass a variable to a function to call an enum and return a value from the enum? If this is a common question, I apologize, I'm new to c++ and might be using the wrong key words when I search.

The compile error I receive is

Compilation error: cannot convert 'String' to 'getValue' ininitialization

enum getValue {     monday = 20,     tuesday = 30,     wednesday = 40,     thursday = 50,     friday = 60,     saturday = 70,     sunday = 80,     everyday = 90   };String settingValue(String settingName){    getValue value = settingName;    // getValue value = monday; <-- this works, although I'd like to call it with settingName instead of the hard coded text    return value;}

Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>