Changing pointer passed to a function as argument
June 14, 2012
Permutations of list of elements with repeated values
June 14, 2012

Function Templates in C++


Overloading template functions:

Template functions can be overloaded with usual functions or other template function. In case they are overloaded with usual function, the non-template function will only be called in case of exact match. For example:

    template<class T> void fun(T x, T y)
    {
        cout << "Template" << endl;
    }
    void fun(int w, int z)
    {
        cout << "Non-Template" << endl;
    }
    int main()
    {
        fun( 1 ,  2 );          // Non-Template. Exact Match
        fun('a', 'b');          // Template.
        fun( 1 , 'b');          // Non-Template. Erroneous to call template
        fun<char>('a', 'b');    // Template. Explicit Template call
    }

Next: Example …

1 Comment

  1. SEO says:

    Great goods from you, man. I’ve understand youir stuff previous to
    and you’re just too fantastic. I really like
    what you’ve acquired here, certainly like what you’re
    stating and the way bby which you are saying
    it. You mwke it enjoyable and you continue to care for to keep
    it sensible. I can not wait to read far more from you.
    That is actually a great website.

Leave a Reply

Your email address will not be published. Required fields are marked *