In an Article The case for D I saw this C++ expression:
object.template fun<arg>()
can anyone explain it?
EDIT: Thanks Mark, I see now that is is indeed a duplicate. But as it is just a side note in a long more comprehensive answer I will just condense the specific answer here in an example.
#include <iostream>
using namespace std;
template <typename T>
struct A
{
T y;
void write()
{
y.T::template print<int>(); // GOOD: I have seen often
y.template print<int>(); // GOOD: shortcut, I did not know
y.print<int>(); // ERROR: I have seen this work on old compiler
}
};
struct B
{
template <typename T>
void print() {cout << "print b" << endl;}
};
int main ()
{
A<B> a;
a.write();
}