Re: Probleme d'executions
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| //ARTICLE.H
#include <iostream>
#include <string>
class CArticle
{
private:
unsigned int m_uRef;
std::string m_Nom;
float m_fPrixHT;
unsigned int m_uQte;
public:
CArticle(unsigned int,const std::string&,float); //On connait pas la quantité dans ce contructeur;
CArticle(unsigned int,const std::string&,float,unsigned int); //On connait la quantité dans ce contructeur;
CArticle(const CArticle & C,const std::string&); //Constructeur de Copie
~CArticle(); //Destructeur
void Ajouter(unsigned int); //Ajouter un nombre à la quantité
void Retirer(unsigned int); //Retirer un nombre a la quantité
float CalCulerPrix(); //Calcule du prix TTC
//void Afficher(); //Fonction d'affichage du prix
friend std::ostream& operator<<(std::ostream&,CArticle); //Surchage de l'operateur <<
}; |
Code:
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
//Article.CPP
#include "ARTICLE.H"
//On connait pas la quantité dans ce contructeur;
CArticle::CArticle(unsigned int uRef,const std::string& Nom,float fPrixHT)
{
m_uRef=uRef;
m_Nom = Nom;
m_fPrixHT=fPrixHT;
m_uQte=0;
}
CArticle::CArticle(const CArticle & C,const std::string& Nom)
{
m_Nom = Nom;
m_uRef=C.m_uRef;
m_uQte=C.m_uQte;
m_fPrixHT=C.m_fPrixHT;
}
//On connait la quantité dans ce contructeur;
CArticle::CArticle(unsigned int uRef,const std::string& Nom,float fPrixHT,unsigned int uQte)
{
m_uRef=uRef;
m_Nom = Nom;
m_fPrixHT=fPrixHT;
//CArticle(uRef,pNom,fPrixHT);
m_uQte=uQte;
}
CArticle::~CArticle()
{
}
//Ajouter un nombre à la quantité
void CArticle::Ajouter(unsigned int Nb=0)
{
m_uQte=m_uQte+Nb;
}
//Retourne le stock quand on ajoute un nombre à la quantite
void CArticle::Retirer(unsigned int Nb=0)
{
m_uQte=m_uQte-Nb;
}
//Retourne le stock enlever un nombre à la quantite
float CArticle::CalCulerPrix()
{
const float TVA=19.6f;
return (m_uQte*(m_fPrixHT+(m_fPrixHT*(TVA/100))));
}
//Fonction d'affichage du prix
/*void CArticle::Afficher()
{
std::cout << "Nom :" << m_Nom << std::endl;
std::cout << "Quantité :" << m_uQte << std::endl;
std::cout << "Prix TTC :" << CalCulerPrix() << std::endl;
}
*/
std::ostream& operator<<(std::ostream& cS,CArticle article)
{
cS << "Nom : " <<article.m_Nom << std::endl;
cS << "Quantite : " << article.m_uQte << std::endl;
cS << "Prix TTC : "<< article.CalCulerPrix() << std::endl;
return cS;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//T_Arcticle
#include "ARTICLE.H"
void main()
{
std::cout <<"-----------------------------" std::<<endl;
std::cout <<"|Test de la classe CArticle |" std::<<endl;
std::cout <<"-----------------------------" std::<<endl;
CArticle cArt(1,"Art",12.1f);
CArticle cArt2(cArt);
CArticle cArt3(1,"Foot",12.1f);
//cArt.Afficher();
cout<<cArt2;
} |
Voila ton code transformé avec des std::string...
Je crois que j'ai trouvé ce qui n'allait pas dans ton code d'ailleurs :
Code:
1 2 3 4 5 6 7 8 9 10
| CArticle::CArticle(unsigned int uRef,char* pNom,float fPrixHT,unsigned int uQte)
{
m_uRef=uRef;
strcpy(m_pNom,pNom); // Ligne 1
m_pNom=new char[DIM]; // Ligne 2
m_fPrixHT=fPrixHT;
//CArticle(uRef,pNom,fPrixHT);
m_uQte=uQte;
} |
Dans la ligne 1 tu copie la chaine, mais tu n'alloue la mémoire qu'a la ligne 2...
Donc je pense que quand strcpy test ses argument il trouve m_pNom qui pointe sur rien....
[édit]Normalement c'est correct maintenant[\édit]