Here is my simplified code:
template<unsigned Size>
class Sequence
{
public:
template<unsigned N>
Sequence<Size - N> chop() const;
};
template<unsigned Size>
Sequence<Size - 1> chop1(Sequence<Size> const& seq)
{
return seq.chop<1>();
}
int main()
{
Sequence<2> seq;
chop1(seq);
}
Since I didn't provide a body for Sequence::chop()
it's not going to link, but it should still compile. Well, it doesn't and I don't understand why. I get the following compiler output:
$ g++ -c test.cpp
test.cpp: In function ‘Sequence<(Size - 1)> chop1(const Sequence<Size>&)’:
test.cpp:12:24: error: expected primary-expression before ‘)’ token
return seq.chop<1>();
^
test.cpp: In instantiation of ‘Sequence<(Size - 1)> chop1(const
Sequence<Size>&) [with unsigned int Size = 2u]’:
test.cpp:19:14: required from here
test.cpp:12:20: error: invalid operands of types ‘<unresolved
overloaded function type>’ and ‘int’ to binary ‘operator<’
return seq.chop<1>();
^
So, the compiler doesn't seem to realise Sequence::chop()
is a templated member function. When that happens with types, you can nudge you compiler with an explicit typename
. Is there a similar trick for templated member functions?