I wrote this answer . Why is this code not compiling under g ++ while it is compiling under VC ++?
How can I make portable code?
My code is:
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 }
Check it out in the online compiler under g ++
Take a look at the online compiler in MSVC ++
source share