-4
我有做简单的getter谁赛格返回故障,我不kwow哪里出了问题:消气赛格故障
有一类“游戏”谁containt两名球员和一个托盘:
> #ifndef PARTIE_H
> #define PARTIE_H
>
> #include <string>
> #include <iostream>
>
> class partie {
> class joueur * joueur1;
> class joueur * joueur2;
> class plateau * jeu;
>
> public:
> partie();
> void initialize(std::string nomj1, std::string nomj2, int tailleplateau);
> int info();
> ~partie();
>
> };
>
> #endif // PARTIE_H
在.cpp:
> #include "partie.h"
> #include "joueur.h"
> #include "plateau.h"
> #include <string>
> #include <iostream>
>
> partie::partie() {
> plateau * jeu = new plateau(0);
> joueur * joueur1 = new joueur("test", 1);
> joueur * joueur2 = new joueur("test2", 2);
>
> }
>
> void partie::initialize(std::string nomj1, std::string nomj2, int
> tailleplateau) {
> plateau * jeu = new plateau(tailleplateau);
> joueur * joueur1 = new joueur(nomj1, 1);
> joueur * joueur2 = new joueur(nomj2, 2); }
>
> int partie::info() { return joueur1->getIdentifiant();
>
> }
>
>
> partie::~partie() {
>
> }
类球员:
> #ifndef JOUEUR_H
> #define JOUEUR_H
> #include <string>
> #include <iostream>
>
> class joueur {
> std::string nom;
> int identifiant;
>
> public:
> joueur();
> joueur(std::string name, int num);
> std::string getName();
> int getIdentifiant(); };
>
> #endif // JOUEUR_H
在.cpp
> #include "joueur.h"
> #include <string>
> #include <iostream>
>
> joueur::joueur() {
> this->nom="DEFAULT";
> this->identifiant=0; }
>
> joueur::joueur(std::string name, int num) {
> this->nom=name;
> this->identifiant=num; }
>
> int joueur::getIdentifiant() {
> return identifiant; }
>
> std::string joueur::getName() {
> return nom; }
任何人看到错误?谢谢你的帮助
main.cpp中: 的#include “mainwindow.h” 的#include <的QApplication> 的#include “partie.h” INT主(INT的argc,字符* argv的[]){ 的QApplication一个( argc,argv); // MainWindow w; //w.show(); partie * newgame; newgame-> initialize(“dylan”,“bob”,13); newgame-> info(); return a.exec(); } – rebug
出于某种原因,你在'joueur'中正确做了事,但在'partie'中做错了。 – molbdnilo