Visual Studio 中的 lcr 游戏 c++ LINK 2019 错误

lcr game c++ LINK 2019 error in Visual Studio

本文关键字:LINK 2019 错误 c++ 游戏 Studio 中的 lcr Visual      更新时间:2023-10-16

我目前正在做一个周日的学校项目。 这是使用Visual Studio 2017 C++的LCR骰子游戏。 我无法通过 2 链接 2019 错误。我已经包含了定义和调用这些函数的所有实例的代码。 我试图改变我称呼它们的方式,并试图删除静态播放器::d勃起,但没有运气。 因为它是一个链接器错误,Visual Studio 直到编译时才会找到它。 我试图寻找答案,但我找不到任何特定于我的问题。任何帮助将不胜感激。 谢谢。 以下是确切的错误:

"LNK2019    unresolved external symbol "public: void __thiscall 
Player::setName(void)" (?setName@Player@@QAEXXZ) referenced in function 
_main   LCR Game    C:UsersdocmoDesktopSNHU filesIT 312 C++ 
ProgrammingLCR GameLCR GameLCR Game.obj  1"

"LNK2019    unresolved external symbol "public: static void __cdecl 
Player::directions(void)" (?directions@Player@@SAXXZ) referenced in 
function _main  LCR Game    C:UsersdocmoDesktopSNHU filesIT 312 C++ 
ProgrammingLCR GameLCR GameLCR 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;
}

我发现了我的问题。 这是一个初学者愚蠢的错误。 即使我将Microsoft Studio 中的文件添加到我的项目中,它也没有包含它们。 我必须在服务器资源管理器中选择每个文件,然后选择"项目",然后包含在项目中。 感谢您的所有帮助。