Advertisement
Mastercpp

Untitled

Nov 17th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class tipo>
  5. tipo valor(tipo v){
  6.     return v;
  7. }
  8.  
  9. //auto seria casi lo mismo que el template
  10. auto retornarValor(auto n){
  11.     return n;
  12. }
  13.  
  14. int main(){
  15.    
  16.     cout << valor("uno") << endl;
  17.     cout << valor(10) << endl;
  18.     cout << valor('A') << endl;
  19.     cout << "------------------\n\n";
  20.     //probando a la funcion de tipo auto
  21.     cout << retornarValor(20) << endl;
  22.     cout << retornarValor("rosado") << endl;
  23.    
  24.     cin.get();
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement