If you'll add a type cast in inddexing, your snippet will work (either of them):
echo capital[ITALY.int]
And Byou can omit type in variable declaration altogether:
var capital = ["Rome", "Berlin", "Lisbon"]
But if the point is to just use explicit values for
Thanks for the help Araq.
The Nim enum behaves differently so I think this code reproduces better the Cpp
code behaviour.
const
ITALY = 0
GERMANY = 1
PORTUGAL = 2
var capital: array = ["Rome", "Berlin", "Lisbon"]
echo capital[PORTUGAL]
Sorry
I did not know this is possible. Seems very interesting.
No, arrays can use enums as the index type (and I use this feature all the
time):
type country = enum
ITALY,
GERMANY,
PORTUGAL
var capital: array[country, string] = ["Rome", "Berlin", "Lisbon"]
echo capital[ITALY]
Sorry for the noobish question. I want to understand how using the enums like
in C/C++
// Example program
#include
#include
using namespace std;
int main()
{
enum country {ITALY, GERMANY, PORTUGAL};
string capital[] = {"Rome", "Berlin", "Lis