I try to use default parameters in my template, like this
#include <iostream>
using namespace std;
template <typename S, typename T=int>
S myadd(T a, T b)
{
S tmp = a + b;
return tmp;
}
int main()
{
int a = 1, b = 2;
float i = 5.1, j = 5.2;
cout << myadd<int, int>(i, j);
cout << myadd<float>(a, b);
return 0;
}
Then g++ myadd.cpp
It shows error:
default template arguments may not be used in function templates without -std=c++0x or -std=gnu++0x
Why does this happen?