Je suis débutant en C++ j'essai de faire un petit programme qui a aucun intérêt à par me permettre de voir si jai bien compris mais il y a deux erreur que je ne comprend pas.
Code : Tout sélectionner
#include <iostream.h>
#include <math.h>
class POINT
{
private:
float X,Y,Z;
public:
POINT();
POINT(float A,float B);
POINT(float A,float B, float C);
T();
T(float Z);
T(float P1, float P2);
T(float P1, float P2, float P3);
float operator=(POINT P);
void Voir();
};
POINT::POINT()
{
X=0;
Y=0;
Z=0;
};
POINT::POINT(float A, float B)
{
X=A;
Y=B;
Z=5;
};
POINT::POINT(float A,float B, float C)
{
X=A;
Y=B;
Z=C;
};
POINT::T()
{
X-=5;
Y-=4;
Z-=3;
};
POINT::T(float P1)
{
Z=P1;
};
POINT::T(float P1, float P2)
{
X=P1;
Y=P2;
};
POINT::T(float P1, float P2, float P3)
{
X=P1;
Y=P2;
Z=P3;
};
float POINT::operator=(POINT V1)
{
float R;
R=(X*X)+(Y*Y)+(Z*Z);
R=sqrt(R);
return R;
};
void POINT::Voir()
{
cout<<"\nLe point est defini par X="<<X<<", Y="<<Y<<", Z="<<Z<<"\n\n\n\n\n";
};
void main()
{
float d;
POINT P1();
cout<<"\n---Affichage du point P1---\n";
P1.Voir();//erreur ici le compilateur me met : "left of'.Voir' must have class/struct/union"
POINT P2(2,3);
cout<<"\n---Affichage du point P2---\n";
P2.Voir();
POINT P3(1,3,5);
cout<<"\n---Affichage du point P3---\n";
P3.Voir();
P3.T();
cout<<"\n---Affichage de P3 apres apllication de la fonction T()---\n";
P3.Voir();
P3.T(3,4);
cout<<"\n---Affichage de P3 apres apllication de la fonction T(3,4)---\n";
P3.Voir();
P3.T(4,5,8);
cout<<"\n---Affichage de P3 apres application de la fonction T(4,5,8)---\n";
P3.Voir();
cout<<"\n---Distance par rapport au centre du point P3---\n";
d= P3;//erreur ici le compilateur me met : "binary'=' : no operator defined which takes a right-han operand of type 'class POINT' (or there is not acceptable conversion)
cout<<"\nd="<<d<<endl;
}
La seconde j'ai essayer de faire une surcharge d'opérateur pour voir comment ça fonctionne mais là j'ai pas du avoir tout compris (oui je sais j'aurais pu faire ça avec une fonction).
Est-ce que quelquun peut éclairer ma lanterne svp?
Merci

