This code with and without the .template
keyword seems to work fine. I am confused why this is so.
#include <iostream>
using namespace std;
struct MyS{
int j;
float y;
template<typename T>
void foo(T a) {
T b = (a /T(3)) * T(2);
cout << "b = " << b << endl;
}
};
int main()
{
MyS M;
M.j = 44;
M.y = 34.257;
M.foo<int>(M.j);
M.foo<float>(M.j);
M.template foo<int>(M.y); // no compilation error - works just as well.
M.template foo<float>(M.y);
return 0;
}
The output is
b = 28
b = 29.3333
b = 22
b = 22.838