我目前正在上周日的学校项目。这是一个使用Visual Studio 2017的C ++ LCR Dice游戏。我无法摆脱2 link2019错误。我已经包含了定义和调用这些函数的所有实例的代码。我试图改变调用它们的方式,并试图删除静态的Player :: directions,但是没有运气。因为它是一个链接器错误,所以Visual Studio直到编译时才找到它。我试图寻找答案,但是找不到与我的问题有关的任何内容。任何帮助,将不胜感激。谢谢。 这是确切的错误:
"LNK2019 unresolved external symbol "public: void __thiscall
Player::setName(void)" (?setName@Player@@QAEXXZ) referenced in function
_main LCR Game C:\Users\docmo\Desktop\SNHU files\IT 312 C++
Programming\LCR Game\LCR Game\LCR Game.obj 1"
和
"LNK2019 unresolved external symbol "public: static void __cdecl
Player::directions(void)" (?directions@Player@@SAXXZ) referenced in
function _main LCR Game C:\Users\docmo\Desktop\SNHU files\IT 312 C++
Programming\LCR Game\LCR Game\LCR Game.obj 1"
这是C ++代码:
Player.h:
#pragma once
#include "stdafx.h"
#include <iostream>
#include "Dice.h"
class Player
{
public:
int chips;
int numPlayers;
std::string name = "";
Player() = default;
void setName();
void setChips();
int checkChips();
static void directions();
};
Player.cpp:
#include "stdafx.h"
#include "Player.h"
#include "Dice.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace System;
using namespace System::IO;
void Player::setName()
{
std::cin >> name;
}
...<more code>
void Player::directions() //display directions to player
...<more code>
LCR Game.cpp
// LCR Game.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <time.h>
#include "Dice.h"
#include "Player.h"
using namespace std;
...<more code>
for (int i = 0; i < numPlayers; i++) //loop to set names and chips for each
player
{
cout << "Enter player name: " << endl;
players[i].setName();
players[i].chips = 3;
}
Player::directions(); //display game rules to player
return 0;
}
答案 0 :(得分:0)
我发现了问题。这是一个初学者的愚蠢错误。即使我将Microsoft Studio中的文件添加到了项目中,也没有包含这些文件。我必须在服务器资源管理器中选择每个文件,然后选择“项目”,然后包含在项目中。感谢您的所有帮助。