Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Can you compile the following template function code?

Reply
Thread Tools

Can you compile the following template function code?

 
 
George2 George2 is offline
Senior Member
Join Date: Feb 2008
Posts: 108
 
      03-06-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
How to compile the following source code in VC6// I have error inVC++6 but compile ok in GCC fAnSKyer C++ 2 06-07-2009 07:57 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
Explicit template instantiation from template function doesn't compile? Fernando Cuenca C++ 4 09-06-2004 04:06 PM
RE: The Web server reported the following error when attempting to create or open the Web project located at the following URL: <URL> =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?= ASP .Net 0 06-07-2004 07:36 AM



Advertisments