Can you compile the following template function code?

Discussion in 'C Programming' started by George2, Mar 6, 2008.

  1. George2

    George2

    Joined:
    Feb 12, 2008
    Messages:
    108
    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
     
    George2, Mar 6, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Razvan
    Replies:
    7
    Views:
    1,239
    Babu Kalakrishnan
    Aug 24, 2004
  2. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    cannot compile the following example code (person-pointer)

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Mar 25, 2006, in forum: C++
    Replies:
    26
    Views:
    678
    Alex Buell
    Mar 31, 2006
  3. Nagaraj
    Replies:
    1
    Views:
    916
    Lionel B
    Mar 1, 2007
  4. 008worker@gmail.com
    Replies:
    0
    Views:
    295
    008worker@gmail.com
    Mar 7, 2008
  5. fAnSKyer
    Replies:
    2
    Views:
    567
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page