我的标题和.cpp文件中的错误
Error in my header and .cpp files
可能的重复:
什么是未定义的参考/未解决的外部符号错误,我该如何修复?
嘿,我在游戏中遇到了这个错误。我有一个标题和.cpp文件以提出问题,因此显然是在此问题。但是我一直在查看标题和.cpp文件,我找不到问题。这是错误:
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Questions::Questions(void)" (??0Questions@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'questions''(void)" (??__Equestions@@YAXXZ) C:UsersConorDocumentsCollegeDKIT - Year 2 - RepeatDKIT - Year 2 - Semester 1 - RepeatGames ProgrammingMillionaireMillionaireMain.obj Millionaire
这是文件:
Questions.h
#ifndef QUESTIONS_H
#define QUESTIONS_H
#include <string>
#include <algorithm>
#include <map>
using namespace std;
class Questions
{
public:
Questions();
Questions(string question,string correctAnswer, string wrongAnswer1,string wrongAnswer2,string wrongAnswer3);
void shuffle(string *array, int n);
string getQuestion();
string getCorrectAnswer();
string* getAnswers();
bool checkAnswer(string answer);
void questionStore();
void addQuestion(int level, Questions *question);
Questions* printQuestion(int level);
private:
string question;
string correctAnswer;
string* pAnswers;
multimap<int,Questions*> map;
};
#endif
Questions.cpp
#include "Questions.h"
using namespace std;
Questions::Questions(string question,string correctAnswer, string wrongAnswer1,string wrongAnswer2,string wrongAnswer3)
{
this->question = question;
this->pAnswers = new string[4];
this->pAnswers[0]=wrongAnswer1;
this->pAnswers[1]=wrongAnswer2;
this->pAnswers[2]=wrongAnswer3;
this->pAnswers[3] =correctAnswer;
this->shuffle(this->pAnswers,4);
this->correctAnswer = correctAnswer;
}
void Questions::shuffle(string *array, int n)
{
random_shuffle(&this->pAnswers[0],&this->pAnswers[4]);
}
string Questions::getQuestion()
{
return this->question;
}
string Questions::getCorrectAnswer()
{
return this->correctAnswer;
}
string* Questions::getAnswers()
{
return this->pAnswers;
}
bool Questions::checkAnswer(string answer)
{
if(this->correctAnswer.compare(answer)==0)
{
return true;
}
return false;
}
void Questions::questionStore()
{
Questions *q1 = new Questions("Whats the oldest known city in the world?", "Sparta" , "Tripoli" , "Rome", "Demascus");
Questions *q2 = new Questions("What sport in the olympics are beards dissallowed?", "Judo", "Table Tennis" , "Volleyball", "Boxing");
Questions *q3 = new Questions("What does an entomologist study?", "People" , "Rocks" , "Plants", "Insects");
Questions *q4 = new Questions("Where would a cowboy wear his chaps?", "Hat" , "Feet" , "Arms", "Legs");
Questions *q5 = new Questions("which of these zodiac signs is represented as an animal that does not grow horns?", "Aries" , "Tauris" , "Capricorn", "Aquarius");
Questions *q6 = new Questions("Former Prime Minister Tony Blair was born in which country?", "Northern Ireland" , "Wales" , "England", "Scotland");
Questions *q7 = new Questions("Duffle coats are named after a town in which country?", "Austria" , "Holland" , "Germany", "Belgium");
Questions *q8 = new Questions("The young of which creature is known as a squab?", "Horse" , "Squid" , "Octopus", "Pigeon");
Questions *q9 = new Questions("The main character in the 2000 movie ""Gladiator"" fights what animal in the arena?", "Panther" , "Leopard" , "Lion", "Tiger");
addQuestion(1,q1);
addQuestion(1,q2);
addQuestion(1,q3);
addQuestion(2,q4);
addQuestion(2,q5);
addQuestion(2,q6);
addQuestion(3,q7);
addQuestion(3,q8);
addQuestion(3,q9);
}
void Questions::addQuestion(int level, Questions *question)
{
map.insert(pair<int,Questions*>(level,question));
}
Questions* Questions::printQuestion(int level)
{
multimap<int, Questions*>::iterator it;
pair<multimap<int, Questions*>::iterator,multimap<int, Questions*>::iterator> ret;
ret = map.equal_range(level);
if(ret.first != ret.second)
{
size_t sz = distance(ret.first, ret.second);
size_t idx = rand() % sz;
advance(ret.first, idx);
it =ret.first;
return (*it).second;
}
else
{
return NULL;
}
}
您正在声明Questions::Questions()
,但没有定义它。
它需要默认的构造函数吗?您使用默认构造函数吗?它需要任何特定的实现吗?
在C 11中,您可以写
Question() = default;
在类定义中。在C 03中,您可以提供一个空的实现:
Question() { }
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 如何在文件和行号中抛出错误
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- AMQP-CPP >处理程序中的错误文件描述符
- Xcode OSX上的C++构建失败,出现多个错误文件IO..不可用:在macOS 10.15中引入
- 为什么生成文件返回 g++: 错误: h 文件或目录 make: *** [生成文件:12: 测试] 错误 1?
- 警告:打开错误文件(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.
- Ubuntu C++ 编译器错误: g++: 错误: 文件.cpp: 没有这样的文件或目录
- main.cc:5:30:致命错误:文件夹/file.h:没有这样的文件或目录
- C++ LNK2005"已定义"错误 - 文件引用自身
- C++:模拟餐饮公司计费程序-无法将错误数据输出到错误文件
- 博兰德C++链接器错误c文件包括
- Visual Studio 2015 代码覆盖率错误文件
- 使用system()与Gnuplot进行绘图会导致错误:文件不可读
- 是否存在fseek/ftell可能给出错误文件大小的情况
- g++编译错误.h文件
- c++编译错误:.o文件未找到
- 打开错误文件的错误消息
- Ndk-build输出添加符号错误.文件格式错误