The following code compiles under Visual Studio 2013, and fails to compile under gcc/clang (all tested versions).
clang: error: use 'template' keyword to treat 'write' as a dependent template name
gcc: error: expected primary-expression before ‘int’
Both errors occur where indicated in the code
template <typename Itr>
struct A {
template <typename Other>
void write(Other x) {}
};
template <class T>
struct B {
A<T>& a;
B(A<T>& a) : a(a) {
// error: use 'template' keyword to treat 'write' as a dependent template name
a.write<int>(5);
}
};
int main() {
A<int> a;
// Fine
a.write<int>(5);
B<int> b(a);
}
Experience tells me that Visual Studio is probably wrong, but I'm not sure why this should fail to compile when A<T>
is fully specified, and I'm only wanting to call a template method whose type I specify.