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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -