why enum has problems in qt ?
-
wrote on 20 Apr 2017, 20:39 last edited by
i gave tried many codes to work with enum in qt but always fail
can anyone please help me -
wrote on 20 Apr 2017, 21:13 last edited by VRonin
This is not a Qt problem but general C++ syntax. use enum class instead of
enum
Also please take a look at https://stackoverflow.com/help/how-to-ask for future posts. Other people might have the same problem you have in the future and it would be nice for them to be able to just google it and find it on this forum
-
wrote on 20 Apr 2017, 20:45 last edited by
Could you paste in an example that isn't working for you?
-
wrote on 20 Apr 2017, 20:49 last edited by VRonin
i have problem like that
i have a class calling shared .h file
with 2 enumsenum x { a=3, b=6, c } enum y { a=10, //error b=3,//error d//no error }
and how can i call the both enums in that class
using thier values -
wrote on 20 Apr 2017, 21:10 last edited by
Even though you call the two enums different names ('x' and 'y'), there members live in the same namespace, i.e., you redeclare 'a' and 'b' in the second enum. That doesn't work. It is kinda the same as declaring a variable 'a' twice in the same scope, that also doesn't work... If you have to use the same name 'a' and 'b' in both enums, the only way to really accomplish that (iirc) is to wrap them in different namespaces outside of the class definition. A better solution, though, would be to simply use different names...
-
wrote on 20 Apr 2017, 21:13 last edited by VRonin
This is not a Qt problem but general C++ syntax. use enum class instead of
enum
Also please take a look at https://stackoverflow.com/help/how-to-ask for future posts. Other people might have the same problem you have in the future and it would be nice for them to be able to just google it and find it on this forum
-
This is not a Qt problem but general C++ syntax. use enum class instead of
enum
Also please take a look at https://stackoverflow.com/help/how-to-ask for future posts. Other people might have the same problem you have in the future and it would be nice for them to be able to just google it and find it on this forum
-
Even though you call the two enums different names ('x' and 'y'), there members live in the same namespace, i.e., you redeclare 'a' and 'b' in the second enum. That doesn't work. It is kinda the same as declaring a variable 'a' twice in the same scope, that also doesn't work... If you have to use the same name 'a' and 'b' in both enums, the only way to really accomplish that (iirc) is to wrap them in different namespaces outside of the class definition. A better solution, though, would be to simply use different names...
1/7