I'm trying to compile this code:
class P{
public:
template<typename Color, typename It>
void f(It a, It b, It c) const
{cout << "in p\n";}
};
// If you uncomment these lines, it compiles!!!
//template<typename Color, typename It>
//void f(It a, It b, It c){}
template<typename P>
void g(const P& p)
{
// This line doesn't compile!!!
// Error
// =====
// error: expected primary-expression before ‘int’
// p.f<int,int>(4,3,2);
// ^
//
// error: expected ‘;’ before ‘int’
p.f<int,int>(4,3,2);
}
int main(int argc, char** argv)
{
const P p;
p.f<int,int>(4,3,2);
return 0;
}
with g++: g++ -c -Wall -std=c++11 -pedantic
and I get the following error:
error: expected primary-expression before ‘int’
p.f<int,int>(4,3,2);
^
error: expected ‘;’ before ‘int’
But if you uncomment the lines
//template<typename Color, typename It>
//void f(It a, It b, It c){}
it compiles. Why?
Thanks.