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

标签 c++

我目前正在做一个周日到期的学校项目。这是一个使用 Visual Studio 2017 的 C++ 中的 LCR 骰子游戏。我无法通过 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;
}

最佳答案

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

关于c++ - Visual Studio 中的 lcr 游戏 C++ LINK 2019 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50929560/

相关文章:

c++ - 在存储可以用不同派生类型初始化的基类型成员变量时避免使用 new

c++ - thread_local 变量在线程内不一致

c++ - 成员函数指针和继承

c++ - 将递归更改为更便宜的东西

c++ - 类方法中的新指针必须转换为引用

c++ - 使用 O(n) 空间问题编辑距离解决方案

c++ - 给一个词加一个数字来调用一个变量

c++ - 返回可变大小的位集

c++ - QTextStream 弄乱了它的位置指针

c++ - 在 C 中创建 DLL 并从 C++ 项目链接它