gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:05 25 4
gpt4 key购买 nike

我目前正在做一个周日到期的学校项目。这是一个使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com