amazingjxq
amazingjxq

Reputation: 4677

Strange too few template-parameter-lists error

set<unsigned int> setId;
vector<int> vecNode;
for (size_t i = 0,set<unsigned int>::iterator it = setId.begin(); i < vecNode.size() && it != setId.end(); i++,it++ ){}

the compiler report: error: too few template-parameter-lists

but if I write like this:

set<unsigned int> setId;
vector<int> vecNode;
size_t i = 0;
for (set<unsigned int>::iterator it = setId.begin(); i < vecNode.size() && it != setId.end(); i++,it++ ){}

the compilation succeeds.

so why?

Upvotes: 0

Views: 1436

Answers (1)

Mark Garcia
Mark Garcia

Reputation: 17708

The same reason as why you cannot do

int i = 0, float j = 2.64f;  // ERROR!

With

size_t i = 0, set<unsigned int>::iterator it = setId.begin()

you are actually doing something like the above example, you are defining two variables but with different types, namely size_t and set<unsigned int>::iterator.

Where you can do

int i = 0, j = 1;  // OK

you are also allowed to do something like

for(size_t i = 0, j = 2; ...; ...) ...

in a for-loop statement. i and j in both examples both have the same type, int and size_t respectively.

Upvotes: 4

Related Questions