-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