我有两个类Game
,ApButton
并且我想ApButton
使用Game
属性,所以我想创建这两个友元函数,但我一直收到错误:
`Game` does not name a type
我知道我不应该apbutton.h
在游戏类中添加,但我必须这样做,因为游戏使用ApButton
(从按钮继承的类)你有没有其他解决方案来解决这个问题?
下面是这两个类的代码:
#ifndef GAME_H
#define GAME_H
#include <QtGui>
#include <QWidget>
#include <apbutton.h> //I have to add this
#include <QHBoxLayout>
#include <QTimer>
#include <iostream>
#include <QMouseEvent>
using namespace std;
namespace Ui {
class Game;
}
friend class ApButton;
class Game : public QWidget
{
Q_OBJECT
public:
explicit Game(QWidget *parent = 0);
~Game();
QLabel *bomb_label();
private:
Ui::Game *ui;
ApButton **btn; //that's why I have to include apbutton.h
};
#endif // GAME_H
#ifndef APBUTTON_H
#define APBUTTON_H
#include <QPushButton>
#include <iostream>
#include <QMouseEvent>
#include <game.h>
using namespace std;
class ApButton : public QPushButton
{
Q_OBJECT
public:
explicit ApButton(QWidget *parent = 0);
void setRowCol(int _row,int _col);
void mousePressEvent(QMouseEvent *ev);
private:
string name;
int row;
int col;
Game g; //here is the problem!
};
#endif // APBUTTON_H