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 about 8 years ago
425
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

        Weimar Germany 1919: The Spartacists and the constitution
        Chris Clayton
        Limits AP Calculus
        lakelife62
        Concepts in Biology Final Exam
        mlszala
        Spanish Vocab Flash Cards
        Clarice Thorn
        C1, C2, C3 keywords
        Jessica Phillips
        Revolutions and Turmoil: Russia 1905-1917
        Emily Faul
        Urbanisation
        Jess Molyneux
        Matters of Life and Death - Edexcel GCSE Religious Studies Unit 3
        nicolalennon12
        The Digestive system
        Elena Cade
        MCQ practice for research methods, psychology
        Ben Armstrong
        1PR101 2.test - Část 19.
        Nikola Truong