0

I have a common.h file:

typedef enum {
  num_letters = 26,
  num_directions = 2
} constants;

and another .h file for a class:

#include "Common.h"
using namespace common;
... some code ...
    vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));

I checked the syntax for vector, it should be correct; I am also using c++11 std; However, it gives me the following errors:

error: 'constants::num_directions' is not a type
     vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));

 error: expected unqualified-id before ',' token
     vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));
                                                                                               ^
error: expected ')' before ',' token
 error: expected ')' before ',' token
 error: expected unqualified-id before numeric constant
     vector< vector<uint> > data(constants::num_directions, vector<uint>(constants::num_letters, 0));

and I am not really sure why it is happening, thank you very much in advance!

Muninmuni
  • 33
  • 4
  • 3
    Another error is that you use `constants::num_directions`. For `enum` it is just `num_directions`. Also the `typedef` you use has no effect in C++ (in C it does). If you want to have `constants::num_directions` (which you should) you need to write `enum class constants{...}` or put the regular `enum` in a namespace. – nwp Oct 16 '15 at 12:15
  • 1
    This works fine for me. could you construct a [minimal example](http://stackoverflow.com/help/mcve) of the problem? – Taus Oct 16 '15 at 12:33

1 Answers1

0

You did not provide enough code to reliably reproduce your problem, so i'll venture a wild guess:

From the error messages your compiler emits it looks as if it interprets the whole line as function declaration rather than as variable definition. This can be due to the fact, that, as has been pointed out in the comments, constants::num_directions is not a valid way to use the enumerator of a normal enum. So the compiler parses the line like a function declaration

ResultType f(ArgType1, Argtype2(argname2))

With ResultTyoe being vector<vector<uint>>, ArgType1 being constants::num_directions which it does not recognize as type, ArgType2 is vector<uint> and then it's completely lost because it can not make head or tail of the rest of the line.

Arne Mertz
  • 24,171
  • 3
  • 51
  • 90