Uso de una matriz de biblioteca estándar

#include <array> 
#include <iostream>
 usando el  espacio de nombres estándar;

struct Point {
     int x, y;
};

ostream & operator << (ostream & os, Punto p)
{
    os << ' { ' << px << ' , ' << py << ' } ' ;
    volver os;
}

template <typename T, int N>
 void print (array <T, N> & a)
{
    para ( int i = 0 ; i! = N; ++ i)
        cout << a [i] << ' \ n ' ;
}

int main ()
{
    matriz <Punto, 3 > puntos {{{ 1 , 2 }, { 3 , 4 }, { 5 , 6 }}};
    imprimir <Punto, 3 > (puntos);
    devuelve  0 ;
}

La matriz de biblioteca estándar se declara como:

template <typename T, size_t N>
 struct array {
    T elem [N];
    // otras funciones miembro 
};

 

Supongo que te gusta

Origin www.cnblogs.com/lhb666aboluo/p/12724552.html
Recomendado
Clasificación