"Extern"对象问题:错误:Id 返回 1 个退出状态
"Extern" object problem: error: Id returned 1 exit status
我是Qt的新人。我试着做贪吃蛇游戏。它几乎完成了,但我在编写分数增加功能时遇到了问题。我正在使用"extern"命令以便将一个函数用于另一个类,但Qt给了我一个错误
我不能尝试任何事情,因为我不明白这个问题。(collinding_items代码没有问题。它可以在没有分数的情况下运行。问题是关于"外部"命令(
主.cpp
Score *score = new Score();
scene->addItem(score);
得分.h
类分数:公共QGraphics文本项 {
公共:
Score(QGraphicsItem *parents=0);
void increase();
int getScore();
私人:
int 游戏得分=0; };
得分.cpp
void Score::increase()
{
Gamescore=+20;
setPlainText(QString("Score: ") + QString::number(Gamescore));
}
int Score::getScore()
{
return Gamescore;
}
蛇.cpp
extern Score *score;
QList<QGraphicsItem *> colliding_items = collidingItems();
for(int i=0, n=colliding_items.size(); i<n; ++i)
{
if(typeid(*colliding_items[i])==typeid (Fruit))
{
scene()->removeItem(colliding_items[i]);
delete(colliding_items[i]);
score->increase();
}
}
对"分数"的未定义引用
错误:ID 返回 1 个退出状态
(找不到文件集合2.exe(
我发现了问题。它源自"extern"命令的使用。它必须用作全局。您可以在下面看到我的代码部分。
得分.h
class Score: public QGraphicsTextItem
{
public:
Puan(QGraphicsItem *parents=0);
void increase();
int getScore();
private:
int Gamescore;
};
蛇.cpp
extern Score *scoring;
Snake::Snake()
{
}
void Show()
{
scoring->increase();
}
如果我使用 extern 作为全局,那么我可以在 Snake 中使用 Score.cpp 的 increase(( 函数.cpp
但我还没有学会"如何提出问题以及如何向这个网站添加代码"。
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 为什么系统函数总是在C++中返回已转移的退出状态?
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 试图在崇高中奔跑. 错误 已发生: 收集2.exe: 错误: ld 返回 1 退出状态
- collect2:错误:ld 返回 1 个退出状态未定义的引用
- C++ collect2:错误:ld 返回 1 退出状态
- 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 退出状态
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 当出现错误ld return 1退出状态时,如何编译程序
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- "Extern"对象问题:错误:Id 返回 1 个退出状态
- c++ (C::B) 错误:ld 返回 1 个退出状态
- 在 c++ 中捕获 shell 脚本退出状态
- 对"displayForStudent(int, int const*, double const*, int)"的未定义引用 collect2.exe:错误:ld 返回 1 个退出状态
- 使用类[错误] LD返回1退出状态
- C++从函数返回的 2D 数组,错误:以非零状态退出
- 随机密码生成器的C++循环错误"以非零状态退出"
- Boost.MSM:通过连接伪状态退出正交区域
- c++语法错误:程序以非零状态退出