나는 어려움을 겪고 3 명의 CPU 플레이어에 대해 도미노를 즐길 수있는 프로그램을 가지고 있습니다. 각 CPU 플레이어는 초급, 중급 또는 전문가가 될 수 있으며 각각의 난이도는 자신의 클래스입니다. 내 'Window'클래스 (아래)의 시작 부분에서 3 명의 CPU 플레이어를 시작하면 프로그램이 올바르게 실행됩니다. Window.h에서C++ 함수에서 새 객체를 만들면 프로그램이 충돌합니다.
public:
Window(QWidget *parent = 0);
Intermediate *cpu1;
Beginner *cpu2;
Intermediate *cpu3;
나는 사용자가 게임의 시작 부분에서 CPU의 어려움을 선택할 수 있도록하려면 그러나
Window::Window(QWidget *parent):QDialog(parent) {
cpu1 = new Intermediate;
cpu2 = new Beginner;
cpu3 = new Intermediate;
}
Window.cpp
에서, 그래서 나는 지금이 객체를 생성하는 'Window'내의 함수. 이 함수를 호출하자마자 게임이 멈추고 프로그램이 예기치 않게 종료되었다는 오류 메시지가 나타납니다.
void Window:: startGame(){
cpu1 = new Intermediate;
cpu2 = new Beginner;
cpu3 = new Intermediate;
}
사람이 진행되고 내가 할 수있는 것은 좋은 것이이 문제를 얻기 위해 무엇을 나에게 설명 할 수있을 것입니다 경우.
Intermediate.cpp (Beginner.cpp이 거의 동일)하는 클래스하면 고장의 원인이 좁혀하는 것입니다 시작하는
#include "intermediate.h"
Intermediate::Intermediate()
{
tilePlaced = false;
skipGo = false;
}
void Intermediate::findDoubles(int a[7][2]){
for(int i = 0; i < 7; i++){ // Creates new doubles list after each go.
doublesList[i] = 0;
}
for(int i = 0; i < 7; i++){ // Creates a list of doubles
if ((a[i][0] == a[i][1]) && (a[i][0] != 7)){
doublesList[a[i][0]] = 1;
}
}
}
bool Intermediate::addDomino(){} // Function that finds best domino to replace and returns bool
if(tilePlaced == false){
pass++;
text += "\nPassed turn";
return false;
}
else{
pass = 0;
text += QString("\nPlaced [%1 : %2]").arg(a).arg(b);
return true;
}
}
클래스 정의를 포함하십시오. –
'Beginner'와'Intermediate'의 생성자를 보여줍니다. – timrau
은'중급 * cpu1; 초심자 * cpu2; 중급 * cpu3;'클래스 정의/생성자가 아닙니까? 아니면 어리석은 질문입니까? – hunterge