1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include <iostream>
using namespace std;
template <class T, int n> class tableau
{
T t[n];
public:
tableau();
T & operator [](int);
};
template <class T, int n> tableau<T,n> :: tableau()
{
cout<<"constructeur"<<endl;
}
template <class T, int n> T & tableau<T,n> :: operator [](int indice){return t[indice];}
class point
{
int x, y ;
public :
int getX() const
{
return x;
}
int getY() const
{
return y;
}
point (int abs=1, int ord=1 ) // ici init par défaut à 1
{
x=abs ; y=ord ;
cout << "constr point " << x << " " << y << "\n" ;
}
void affiche () { cout << "Coordonnees : " << x << " " << y << "\n" ; }
point & operator = (const point &point_)
{
x = point_.getX();
y = point_.getY();
}
} ;
int main()
{
tableau<point, 5>tab;
tab[1] = point(5,8);
for(int i=0;i<5;i++)
tab[i].affiche();
return 0;
} |