Can you compile the following template function code?

Joined
Feb 12, 2008
Messages
108
Reaction score
0
Hello everyone,


Here is the code and related compile error information. I am using Visual Studio 2008. Not sure whether you can compile using your compiler? Why Visual Studio 2008 can not deduce template parameter type?

Code:
#include <iostream>

using namespace std;

template <class T> void f(int a) {g (a);}

void g(int a)
{
	cout << a << endl;
}

int main()
{
	f (100); // can not compile, error C2783: 'void f(int)' : could not deduce template argument for 'T'
	// f<int> (100) can compile
	return 0;
}


thanks in advance,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top