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

        An Inspector calls Techniques
        anya14
        A Christmas Carol Quotes
        0serenityrose0
        GCSE REVISION TIMETABLE
        TheJileyProducti
        GCSE AQA Biology 2 Enzymes, Digestion & Enzyme Uses
        Lilac Potato
        GCSE Chemistry C3 (OCR)
        Usman Rauf
        AQA GCSE Chemistry Unit 2
        Gabi Germain
        Physics 2
        Peter Hoskins
        Latin Literature Exam Techniques
        mouldybiscuit
        3.1 Keywords - Marketing
        Mr_Lambert_Hungerhil
        General questions on photosynthesis
        Fatima K
        Core 1.5 Mechanisms
        T Andrews