Overloading of the function templates - Functions

Q.  Can we have overloading of the function templates?
- Published on 17 Jul 15

a. Yes
b. No

ANSWER: Yes
 

    Discussion

  • X   -Posted on 07 Nov 20
    N
  • Raj Singh   -Posted on 12 Oct 15
    You can overload a function template either by a non-template function or by another function template.
    Example:
    class myClass
    {
    public:
    template
    void fun(T x, T y)
    {
    cout << "Template function is called" << endl;
    }

    void fun(int w, int z)
    {
    cout << "Non-template function is called" << endl;
    }
    };

    int main() {
    myClass obj;
    obj.fun( 10 , 20 );
    obj.fun('a', 'b');
    }

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)