2017-11-28 5 views
0

Qt 작성자에서 C++을 사용하여 소규모 게임을 개발 중입니다. "게임이 선언되지 않았습니다"라는 오류가 나타납니다. 나는 game.h를 사용하여 그것을 선언했다. 헤더 파일에 오류가있다. 나는 문제가 어디 있는지 알 수 없다. 제발, 어떤 도움은 매우 appriciated 것입니다.헤더 파일에 선언 오류가 발생했습니다.

#ifndef BALL_H 
#define BALL_H 
#include<QCloseEvent> 
#include <QGraphicsRectItem> 
#include "game.h" //i have declared it here. 




class Ball: public QObject, public QGraphicsRectItem{ 
Q_OBJECT 
public: 
// constructors 
Ball(QGraphicsItem* parent=NULL); 
QTimer *runTimer; 


// public methods 
double getCenterX(); 


public slots: 
// public slots 
void move(); 
void start_timer(); 
void stop_timer(); 
void call_game_fuction(Game *gm); //here i am getting the error(Game) 


private: 
// private attributes 
double xVelocity; 
double yVelocity; 
int counter = 0; 

// private methods 

void resetState(); 
bool reverseVelocityIfOutOfBounds(); 
void handlePaddleCollision(); 
void handleBlockCollision(); 
}; 

#endif // BALL_H 

은이는 CPP의 fuction를 당신이 순환 종속성이

Game *obj1 =new Game(); 
      game_function *obj2 = new game_function(); 
void Ball::call_game_fuction(Game *gm) 
{ 
gm->set_background(); 

} 

선생님이 내 game.h 파일

#ifndef GAME_H 
#define GAME_H 

#include <QGraphicsView> 
#include <QGraphicsScene> 
#include "Ball.h" 
#include "Paddle.h" 
#include "Block.h" 
#include<QPushButton> 

class Game:public QGraphicsView{ 

Q_OBJECT 

public: 
// constructors 
Game(QWidget* parent=0); 
QPushButton *button; 
QPushButton *button1; 




// public methods 




void start(); 
void createBlockCol(double x); 
void creatBlockGrid(); 
void set_background(); 
void background_Gamewon(); 
void set_buttons(); 

QGraphicsScene* scene2; 




// public attributes 
QGraphicsScene* scene; 
QGraphicsView* view; 


private slots: 
void startgame(); 
void stopgame(); 





private: 
bool gameOver; 
Ball *ball; 
Paddle *pad; 
Block *bl; 


}; 

#endif // GAME_H 
+2

컴파일러에서 선언되지 않았다면 "보이지 않는"헤더에 대한 주석에서 "여기에 선언했습니다"라고 주장해도 도움이되지 않습니다. 당신은 * 당신이 그것을 선언했다고 생각하고, 컴파일러는 당신에게하지 않았다고 말한다. 헤더를 보여주십시오. 헤더 파일과 소스 파일 모두 오류 (예 : [mcve])를 재현하고 게시 * 할 때까지 헤더 파일과 소스 파일을 모두 잘라내십시오. (트리밍 과정에서 문제가 발견되지 않으면 가능성이 있습니다.) – DevSolar

+1

François Andrieux를 인용 - [Minimal, Complete, Verifiable example] (https://stackoverflow.com/help/mcve) 제공을 고려하십시오. 예를 들어 특정 파일이 필요하며 파일에 포함 된 내용을 추측 할 수 없습니다. 코드를 스스로 시험해 볼 수 있다면 문제를 쉽게 식별 할 수 있습니다. 중요한 이름을 사용하면 코드를 이해하고 추론하는 데 도움이 될 수 있습니다. – JTejedor

+1

시도 : #include 뒤 게임 클래스 쓰기; – Taz742

답변

4

되는 파일입니다. Ball.h에는 game.h가 포함되고 game.h에는 Ball.h가 포함됩니다. 컴파일러가 해결할 수없는 상황입니다. 어느 쪽도 먼저 포함될 수 없기 때문에 해결할 수 없습니다.

game.h에 #include "Ball.h"이 필요하지 않은 것으로 보입니다. 대신 다음 선언을 사용하십시오.

class Ball; 

game.h를 컴파일하기에 충분합니다.

+0

각하, 그것을 해결되었습니다. 나는 너에게 대답했다. –

관련 문제