problème avec un template
voilà.
Je me suis risqué aux template qui restent qqchose d'assez obscure pour moi. J'ai une classe qui représente Un point avec un tableau de 2 valeurs et d'autres choses (non indiquées) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| template<typename T> class Point //un Point =T[2] +...
{
public:
Point<T>(){/***/};
Point<T>(const Point<T>& c) : iP(c.iP){};
Point<T>(const T c[2]) : iP{c[0],c[1]} {};
Point<T>(const T c0, const T c1) : iP{c0,c1} {};
Point<T> &operator=(const Point<T>& c){iP[0] = c.iP[0];iP[1] = c.iP[1];};
Point<T> &operator=(const T c[2]){iP[0]=c[0];iP[1]=c[1];};
T operator[] (size_t idx ) const {return iP[ idx ];};
private:
T iP[2];
}; |
Voilà ça plante ici :
Code:
unVecteur.push_back(Point<int>(2,1));
le compilateur m'indique :
Code:
1 2
| error: array used as initializer
In member function Point<T>& Point<T>::operator=(const Point<T>&)[with T = int]: ... |
J'imagine qu'il y a une grosse bêtise, mais je ne comprends pas pourquoi il veut utiliser l'operateur = en fonctionnantcomme si l'objet n'était pas construit ( ?). Dur, dur le cpp ;)