1 pièce(s) jointe(s)
afficher mon objet stocks
Bonjour,
J'aimerais afficher mon objet stock et j’obtiens une erreur sémantique... donc il y a quelques choses que je comprends pas mais quoi ? voici le code
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
| /*
* stockarmes.h
*
* Created on: 14 janv. 2021
* Author: vincent
*/
#ifndef STOCKARMES_H_
#define STOCKARMES_H_
#include <iostream>
#include <string>
#include "Arme.h"
class Stockarmes
{
public:
Stockarmes();
Stockarmes(std::string monArme, int nombreArme, int stock );
~Stockarmes();
void increment(std::string monArme, int nombreArme, int stock);
void decrement(std::string monArme, int nombreArme, int stock);
void changerArme(std::string nomNouvelleArme, int degatsNouvelleArme);
void afficherEtatstock() const;
private:
std::string m_monArme;
int m_nombreArme ;
int m_stock;
Arme *m_arme; //pointeur
};
#endif /* STOCKARMES_H_ */ |
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
|
/*
* stockarmes.cpp
*
* Created on: 14 janv. 2021
* Author: vincent
*/
#include "Stockarmes.h"
using namespace std;
Stockarmes::Stockarmes() : m_arme (10), m_stock(10),m_nombreArme(0){
// TODO Auto-generated constructor stub
}
Stockarmes::~Stockarmes() {
// TODO Auto-generated destructor stub
}
void Stockarmes::increment(string monArme, int stock, int nombreArme): m_monArme(""), m_stock(10), m_nombreArme (0)
{
if (monArme)
{
stock = stock + nombreArme;
}
}
void Stockarmes::decrement(string monArme, int stock, int nombreArme): m_monArme(""), m_stock(10),m_nombreArme (0)
{
if (monArme)
{
if (stock > 0)
{
stock =stock-nombreArme;
}
}
}
void Stockarmes::afficherEtatstock() const
{
cout << "nom de l'arme : " << m_monArme << endl;
cout << "Quantité : " << m_stock << endl;
m_arme->afficher();
} |
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
| #include <iostream>
#include <string>
#include "Personnage.h"
#include "Stockarmes.h"
using namespace std;
int main()
{
// Création des personnages
Personnage david, goliath("Epée aiguisée", 20);
// Au combat !
goliath.attaquer(david);
david.boirePotionDeVie(20);
goliath.attaquer(david);
david.attaquer(goliath);
goliath.changerArme("Double hache tranchante vénéneuse de la mort", 40);
goliath.attaquer(david);
// Temps mort ! Voyons voir la vie de chacun...
cout << "David" << endl;
david.afficherEtat();
cout << endl << "Goliath" << endl;
goliath.afficherEtat();
cout << "etat du stock" << endl;
Stockarmes stocks () const;//-------------------------------------------------------------------ici
stocks.afficherEtatstock();//-------------------------------------------------------------------ici
return 0;
} |
Pièce jointe 588778