Article The case for Dで、次のC++ 式を見ました。
object.template fun<arg>()
誰もそれを説明できますか?
編集:マークに感謝します。これは実際に重複していることがわかります。しかし、これはより包括的な回答の補足事項にすぎないため、ここで具体的な回答を例に要約します。
#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();
}