defining a function with template after main()

Dear all,

I have the following code:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
int main()
{
void print(T var);
    print(110);
}
template <class T>
void print(T var)
{
    cout << var << endl;
}

and get the following error with g++ frontend:
1
2
3
tem.cpp:5:12: error: variable or field ‘print’ declared void
tem.cpp:5:12: error: ‘T’ was not declared in this scope
tem.cpp:6:14: error: ‘print’ was not declared in this scope

At first error, gcc say print isn't define, yes because i can't define print's prototype at main function.
Question:
How can i use a template function that i defined it after main() function. How i define it's prototype into main?
Last edited on
prototype should be placed before main like this (on line 3)

template<class T> void print(T var);

and remove the current line 5 inside main
Topic archived. No new replies allowed.