TEMPLATES (plantillas)

Description

Mind Map on TEMPLATES (plantillas), created by Lot Schacht on 19/05/2016.
Lot Schacht
Mind Map by Lot Schacht, updated more than 1 year ago
Lot Schacht
Created by Lot Schacht over 8 years ago
428
0

Resource summary

TEMPLATES (plantillas)
  1. Se utilizan para declarar un tipo de dato "provisional".
    1. Se declararán variables con datos de cualquier tipo.
      1. El compilador reconocerá este tipo de dato y le dará el trato adecuado dentro del método.
        1. Así que podríamos mandar cualquier tipo de dato a esta plantilla, por ejemplo un 3.72, y el compilador comenzará a tratar a esta variable como un respectivo float.
      2. Reemplazando a int, float, char, string, etc. por un momento.
      3. Se declaran con la palabra reservada "template".
        1. template<class T>
          1. Se declara en la clase.
            1. template <class T> class mypair { T a,b; public: mypair(T first, T second) { a=first; b=second; } T getmax(); };
              1. Se vuelve a declarar antes del método donde se utilizará.
                1. template <class T> T mypair<T>::getmax () { T val; val = a>b? a : b; return val; }
                  1. En este ejemplo, cualquier tipo de valor que llegue a las variables a y b a través del first y second del constructor será tratado como tal dentro del programa.
        Show full summary Hide full summary

        Similar

        OCR Biology AS level (f211) flashcards/revision notes
        Dariush Zarrabi
        Resumo para o exame nacional - Felizmente Há Luar!
        miminoma
        AQA Biology 8.1 structure of DNA
        Charlotte Hewson
        AQA Biology B2 Questions
        Bella Statham
        BELIEVING IN GOD- UNIT 1, SECTION 1- RELIGIOUS STUDIES GCSE EDEXCEL
        Khadijah Mohammed
        Key Biology Definitions/Terms
        courtneypitt4119
        MATTERS OF LIFE AND DEATH - UNIT 1, SECTION 2 - RELIGIOUS STUDIES GCSE EDEXCEL
        Khadijah Mohammed
        Repaso de Revalida Enfermeria 2015
        Francisco Rivera
        untitled 2
        lola_smily
        The Circulatory System
        Johnny Hammer
        Control de enfermedades bucales
        Silvia Castillo Limón