+ Reply to Thread
Results 1 to 2 of 2

Thread: Why my template function does not getting called?

  1. #1

    Why my template function does not getting called?

    Following code always invoke non-template function. Why?

    Code:
    template<typename T>
    T GetData(T objT)
    {
    	return objT ;
    }
    
    int GetData(int nData)
    {
    	return nData ;
    }
    
    Void UseTemplate()
    {
    	float f = 10;
    	int nData = GetData(10) ; //this does not invoke template function. why?
    	nData = GetData(f) ;
    }
    Help.

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    37
    This is called Overload Resolution of Function Template calls.

    Compiler identifies the best match for you and call that function.

    In that way your template function does not getting called for integer data type.

    For float, it will use the template function.

    For more information, visit:
    http://msdn.microsoft.com/en-us/library/s016dfe8.aspx

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts