Where shoud I fix a C++ code about the template? -
when wrote c++ code , compiled clang++ compiler,
error: expected expression template <typename t> ^
was represented.
why did error appeared , how fix it?
#include<iostream> using namespace std; int main() { template <typename t> t sum(t a, t b) { return a+b; } cout <<"sum = " << sum( 2.1, 7.9 ) << endl; return 1; }
you cannot define function within main
. move definition outside
#include <iostream> template <typename t> t sum(t a, t b) { return + b; } int main() { std::cout << "sum = " << sum(2.1, 7.9) << std::endl; return 0; }
wiki
Comments
Post a Comment