Pb C++ Vector Classe différente

nos1886 Messages postés 6 Date d'inscription lundi 17 novembre 2008 Statut Membre Dernière intervention 2 novembre 2012 - 2 nov. 2012 à 14:29
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 - 4 nov. 2012 à 13:24
Bonjour à tous, je suis nouveau sur le forum et j'ai un niveau moyen en langage C++. J'ai un problème d'utlisation de mon vecteur "tablbovin", je ne saisis pas mon erreur et cela fait 3 jours que je cherche pourriez vous m'aider. Je vous joints un extrait de mon code qui pose problème, je précise qu'il s'agit d'un header.



#pragma once
#include "stdafx.h"
#include <vector>


typedef class defbovin {
defbovin(void);
~defbovin(void);
int index;
string espece;
double poid;
double prix;
int mois;
int annee;
int identifiant;
char *sexe;
bool genisse;
};


defbovin::defbovin(void){}
defbovin::~defbovin(void){}


typedef class bovin {

 public:
bovin(void);
~bovin(void);
vector <defbovin> tablbovin;

private :
void PrintAttributOneBovin( int );
};


bovin::bovin(void){}
bovin::~bovin(void){}


/****************************************************************
Objectifs	: Affiche l'ensemble  des attributs d'un  bovin
****************************************************************/
 void bovin::PrintAttributOneBovin(int ligne){


clrscr;
cout<<endl;
cout<<"----- Enr N° "<<ligne<<" ------" <<endl;
cout << "\tNumero d'identification :\t" << &tablbovin[ligne].identifiant << endl;
cout << "\tNé(e) en :\t" << &tablbovin[ligne].mois <<"//"<< &tablbovin[ligne].annee << endl;
cout << "\tSexe :\t" << &bovin.tablbovin[ligne].sexe << endl;
cout << "\tGenisse :\t";

if (&tablbovin[ligne].genisse){
cout << "Oui" << endl;
}else{
cout << "Non" << endl;
}
cout << "\tPoid :\t" << &tablbovin[ligne].poid << endl;
cout << "\tPrix :\t" << &tablbovin[ligne].prix << endl;
}

2 réponses

cptpingu Messages postés 3837 Date d'inscription dimanche 12 décembre 2004 Statut Modérateur Dernière intervention 28 mars 2023 123
Modifié par cptpingu le 12/02/2015 à 16:48
Bonjour.

Sans explication de ton problème difficile de t'aider...
Quel est le comportement attendu ? Le comportement actuel ?

Je vois des choses suspicieuses dans ton code:
- &tablbovin[ligne].poid => Mais que vient faire un "&" ici ? Tu prends l'adresse d'une variable et non sa valeur... "tablbovin[ligne].poid" serait correcte. Pareil partout ou tu as fait cette erreur.
- Évite les "using namespace", voir: http://0217021.free.fr/portfolio/axel.berardino/articles/bon-usage-using-namespace
- Une classe prend une majuscule.
- Un attribut de classe se différencie par un signe. Par exemple "_". tablbovin => _tablbovin.
- Code en anglais si tu le peux.
- Évite les char*, préfère un std::string

________________________________________________________________________
Historique de mes créations, et quelques articles:
[ http://0217021.free.fr/portfolio http://0217021.free.fr/portfolio]
Merci d'utiliser Réponse acceptée si un post répond à votre question
0
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
4 nov. 2012 à 13:24
Yop,
Je rajouterais le fait qu'il n'est pas très propre de mettre du code dans les fichiers header...


@+
Buno, Admin CS
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
0
Rejoignez-nous