未解决的外部问题c ++ [英] Unresolved external issue c++
问题描述
尝试使用外部声明的类对象,但收到错误。
trying to use an externally declared class object, but receiving an error.
wager.h
#ifndef WAGER_H
#define WAGER_H
#include <QString>
void won_color_bets(int cardsDealt);
class Wager
{
int bet;
int payout;
public:
bool didBet;
bool won;
QString colorBet;
QString colorResult;
Wager();
};
extern Wager street1;
#endif // WAGER_H
wager.cpp
wager.cpp
#include "wager.h"
#include "deck.h"
#include<QDebug>
#include<QVector>
#include<QList>
#include"mainwindow.h"
Wager street1;
Wager street2;
Wager street3;
Wager street4;
Wager street5;
mainwindow.cpp
mainwindow.cpp
void MainWindow::street1BetRedClicked()
{
street1.colorBet="Red";
qDebug()<<"street1Red Clicked";
}
mainwindow.obj:-1:error:LNK2001:unresolved external symbolclass Ward street1(?street1 @@ 3VWager @@ A)
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "class Wager street1" (?street1@@3VWager@@A)
debug正在输出 street1Red已点击
>
debug is outputting street1Red Clicked
successfully
推荐答案
以下错误消息告诉您,您没有链接Wager.cpp文件或者您错过了实现一个功能。在你的情况下,你忘了给函数定义 Wager();
Below error message tells you either you haven't linked Wager.cpp file or you have missed implementing one function. In your case you forgot to give function definition to Wager();
:LNK2001:未解析的外部符号class Wager street1
(?street1 @@ 3VWager @@ A)
error: LNK2001: unresolved external symbol "class Wager street1" (?street1@@3VWager@@A)
这个问题,你需要实现 Wager()
某处,在Wager.cpp或Wager.h。
我提供了一个示例实现 Wager :: Wager()
(默认构造函数:function name与类名相同, em>)。
注意:下面的代码还初始化成员初始化列表中的所有类成员。
To fix this issue, you need to implement Wager()
somewhere, either in Wager.cpp or Wager.h.
I provide an sample implementation for Wager::Wager()
(default constructor: function name is the same as class name and takes 0 argument).
Note: Below code also initialize all class members in member initializers list.
Wager::Wager()
:bet(0),
payout(0),
didBet(false),
won(false),
colorBet("blue"),
colorResult("blue)
{
}
这篇关于未解决的外部问题c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!