I'm a new bee to C++. I'm having below errors when tying to compile below templates example copied from "Essential C++", I simply copied the example on the book.
"error : expected ',' or '...' before '< ' token" "error : 'vec' was not declared in this scope
I was wondering what could be the problem, could you help spare some time to give a hint? so much appreciate!
'''
#include <iostream>
template <typename elemType>
void display_message(const string &msg, const vector<elemType> &vec)
{
cout << msg;
for(int ix = 0; ix < vec.size(); ++ix)
{
elemType elem = vec[ix];
cout << elem << ' ';
}
}
int main()
{
int size = 10;
ocnst vector<int> ivec1 = fibon_seq(5);
if (is_size_ok(size))
{
display_message(msg, size);
}
display_message(msg, ivec1);
cout << "Hello world!" << endl;
return 0;
}
'''
vector
defined or declared? – Some programmer dude Jan 17 at 6:54msg
defined inmain
? Where aredisplay_message
,fibon_seq
, andis_size_ok
defined?display_message
takes a string and a vector as arguments, you pass it a string and an int. – Nathan Pierson Jan 17 at 6:56