Value of class elements
I have a class, and I want to find the value of a element in the class.
How do I do that?
Header:
1 2 3 4 5 6 7 8
|
enum class Rank{
two = 2, three, four, five, six, seven, eight, nine, ten, jack, queen,
king, ace
};
struct CardStruct {
Rank r;
};
|
Cpp:
1 2 3 4 5
|
int toStringShort(CardStruct k) {
int verdi = (k.r); //What should I write here to get the value?
return verdi;
}
|
Main:
|
cout << toStringShort(CardStruct{Rank::ace});
|
Here, I would want the output: 14
Cast it to an int.
1 2 3
|
int toStringShort(CardStruct k) {
return static_cast<int>(k.r);
}
|
Last edited on
Thanks!
Topic archived. No new replies allowed.