Reputation: 19
I'm having trouble assigning an element of a pointer vector of object pointers to an object pointer. I'm on a Linux and using Eclipse IDE. If you want to take a look at my problem:
void Parse::parseDatalogProgram(vector<Token*>* tokens)
{
Token* currentToken = tokens[0];
...
}
I'm getting a syntax error saying "cannot convert ‘std::vector’ to ‘Token*’ in initialization", although above doesn't seem to look that way How do I properly fix this?
Upvotes: 1
Views: 348
Reputation: 22690
tokens
is a pointer to vector, not the object or a reference. The C++ way would be changing the function prototype to:
void Parse::parseDatalogProgram(const vector<Token*>& tokens){...}
If that is not possible, you can simply dereference the pointer before using it: Token* currentToken = (*tokens)[0]
Upvotes: 2
Reputation: 16328
Token* currentToken = (*tokens)[0];
Make sure tokens is not null. Why don't you pass a reference, instead?
Upvotes: 2
Reputation: 258588
tokens
is a pointer, not a vector
itself. You can do
tokens->operator[](0);
or
(*tokens)[0];
Upvotes: 5