I wrote this answer. Why this code doesn't compiles under g++ while it compiles under VC++?
How can I make the code portable?
My code:
template<typename T>
inline T sum(T t){
return t;
}
template<typename T, typename... Ts>
inline auto sum(T t, Ts... ts)->decltype(t+sum(ts...)){
return t+sum(ts...);
}
#include<iostream>
int main(){
std::cout<<sum(2.5, 2)<<'\n' //works
<<sum(2, 2.5)<<'\n'; //works
std::cout<<sum(1u, 2.5, 3.f, '0')<<'\n';//doesn't work, don't know why
}
See it in online compiler under g++
See it in online compiler under MSVC++