Why is the following code invalid?
template <typename S, typename T>
struct B{
void f(T t, S s) {t.f<S>(s); }
};
gcc 4.3.4 complains that it “expected primary-expression before ‘>’ token”, i.e. that “S” wasn’t a valid primary-expression.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to specify that
fis a template:C++ doesn’t know this (at this point) since
f’s type depends on the type of the template parameterT. Furthermore, the following syntax would be ambiguous: does<mean the start of a template list or a less-than operator? To help C++ figure that out you need to specify thatfis a template, otherwise C++ cannot parse the following part because the parse itself depends on the type ofT.