Search
 
SCRIPT & CODE EXAMPLE
 

CPP

overloading templates in cpp

// we can overload template just like function 

/*if the template function have same name but differ by
signaturas (number of parameters and their type and their sequence)
then the are said to be overloaded.*/

/*here print function can be used to print a single value or the same value 
multiple times depending upon the parameters passed*/


template <class T>
T print (T a)
{
   cout << a;
}

template <class T>
T print (T a, int n)
{
   for (int i=0; i<n; i++)
   {
       cout << a;
   }
}

int main()
{
    print('a');
    print(1);
    print(1,6);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: CodeChef Starters 30 Division 4 (Rated) Swapping Chefs Way 
Cpp :: default parameter c++ a field 
Cpp :: youtube to facebook link converter 
Cpp :: ternary operator rsut 
Cpp :: is variable sized array are not allowed in c++? 
Cpp :: digits in c++ 
Cpp :: how to type cast quotient of two integers to double with c++ 
Cpp :: case 1 or 2 c++ 
Cpp :: Increase IQ codechef solution in c++ 
Cpp :: Qt asynchronous HTTP request 
Cpp :: && in cpp 
Cpp :: pagesNumbering C++ 
Cpp :: can you add a bool and an int 
Cpp :: ue4 c++ bool to text 
Cpp :: cocos2d c++ linux 
Cpp :: Runtime error(Exit status:153(File size limit exceeded)) c++ 
Cpp :: float to byte array and back c++ with memcpy command 
Cpp :: sfml get position 
Cpp :: c++ string to const char* 
Cpp :: how to print std::string 
Cpp :: clean list widget qt 
Cpp :: 01matrix 
Cpp :: variabili in c++ 
Cpp :: C++ thread header 
Cpp :: C++ How to insert and print array elements? 
Cpp :: how to list directory in c++ 
Cpp :: how to find second smallest element using single loop 
Cpp :: C++ Enumeration Type 
Cpp :: bounded and unbounded solution in lpp 
Cpp :: c++ login 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =