- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的编程类(class)开发一个项目,当我尝试编译它时,我不断收到构建错误 LNK2019。我试过咨询另一个 CPS 专业,他不太确定为什么我总是收到错误。
// File: Asgn7_Skel.cpp
// CPS 150/Fall 2013 Assignment 7 Skeleton
// Modified from Gaddis Program 8-32 to satisfy the assignment
// requirements.
// Skeleton by: Tamisra H. Sanyal
// Completed by: Kyle Abel
// This program lets the user play a game of rock, paper, scissors
// with the computer. The computer's choices are randomly generated.
// Total 10 rounds are played.
// Change the NumRounds constant to play a different number of rounds
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
#include <string>
#include <array>
using namespace std;
// enumerations of choices and outcomes
enum Choices {Rock, Paper, Scissors, Last};
enum Outcomes {ComputerWin, PlayerWin, Tie,};
// Data for one round
struct GameData
{
Choices computerChoice;
Choices playerChoice;
Outcomes result;
}; // end struct
const int NumRounds(10); // number of rounds to play
const int ArraySize(NumRounds); // we will not use index 0
typedef array<GameData, ArraySize> DataStore;
// These constant arrays are used to translate enumeration constants to
// readable descriptions (see line 9 in textbook's program)
const array<string, 3> ChoiceNames = {"Rock", "Paper", "Scissors"};
const array<string, 3> OutcomeNames = {"Computer win", "Player win", "Tie"};
array<int, 3> ResultsTalley = {};
// Function prototypes
void getPlayerChoice(Choices & choice);
Outcomes getRoundResult(const Choices computerChoice, const Choices playerChoice);
void showRoundResult(const Choices computerChoice, const Choices playerChoice,
const Outcomes roundResult);
void showGameResults(const DataStore & results);
int main()
{
Choices computerChoice, playerChoice;
Outcomes roundResult;
int computerPoints = 0, playerPoints = 0; // Point accumulators
DataStore gameResults = {};
srand(time(NULL)); // Give the random generator
int counter; // a seed to start with
int pl_choice;
cout << "CPS 150 Assignment 7 by Kyle Abel\n\n";
cout << "Let's play Rock-Paper-Scissors!\n";
cout << "We will play " << NumRounds << " rounds.\n\n";
// TODO: Add main function code here
for (counter = 0; counter < NumRounds; counter++)
{
computerChoice = static_cast<Choices>(rand() % 3);
getPlayerChoice(playerChoice);
getRoundResult(computerChoice, playerChoice);
showRoundResult(computerChoice, playerChoice, roundResult);
if (Tie)
{
return 0;
}
else if (ComputerWin)
{
computerPoints++;
}
else
playerPoints++;
} // end for
cout << "\nCPS 150 Assignment 7 complete\n\n";
return 0;
} // end main
void showGameResults(const DataStore & results)
{
cout << "Game results\n";
cout << "============\n";
cout << right << setw(5) << "Round" << ' '
<< left << setw(14) << "Player choice"
<< setw(16) << "Computer choice"
<< setw(13) <<"Round result" << endl;
cout << right << setw(5) << "-----" << ' '
<< left << setw(14) << "-------------"
<< setw(16) << "---------------"
<< setw(13) <<"------------" << endl;
for (int k(1); k < results.size(); k++)
{
cout << right << setw(5) << k << ' ' << left
<< setw(14) << ChoiceNames[results[k].playerChoice]
<< setw(16) << ChoiceNames[results[k].computerChoice]
<< setw(13) << OutcomeNames[results[k].result] << endl;
} // end for
cout << endl;
} // end showGameResults
void getPlayerChoice(Choices playerChoice, int PChoice)
{
cout << "Enter your choice, 1 for Rock, 2 for Paper, or 3 for Scissors";
cin >> PChoice;
if (PChoice != 1 || PChoice != 2 || PChoice != 3)
{
cout << "Please Enter a Valid # 1-3" << "\n\n";
cin >> PChoice;
}
else if (PChoice = 1)
{
PChoice--;
static_cast<Choices>(PChoice);
}
else if (PChoice = 2)
{
PChoice--;
static_cast<Choices>(PChoice);
}
else
{
PChoice--;
static_cast<Choices>(PChoice);
}
}
Outcomes getRoundResult(const Choices computerChoice, const Choices playerChoice)
{
if (computerChoice == playerChoice)
{
return Tie;
}
else if ((playerChoice == 1 && computerChoice == 2) ||
(playerChoice == 2 && computerChoice == 3) ||
(playerChoice == 3 && computerChoice == 1) )
{
return ComputerWin;
}
else
{
return PlayerWin;
}
}
void showRoundResult(const Choices computerChoice, const Choices playerChoice, const Outcomes roundResult)
{
if (Outcomes(Tie))
{
cout << "we have tied!";
}
else if (Outcomes(ComputerWin))
{
cout << "I chose " << ChoiceNames[computerChoice] << ", so I win the game! "
<< ChoiceNames[computerChoice] << " beats " << ChoiceNames[playerChoice]
<< ". \n\n";
}
else if (Outcomes(PlayerWin))
{
cout << "I chose " << ChoiceNames[computerChoice] << ", so you won!! "
<< ChoiceNames[playerChoice] << " beats " << ChoiceNames[computerChoice]
<< ". \n\n";
}
}
这些是我在尝试构建项目时不断遇到的错误:
1>------ Build started: Project: ConsoleApplication15, Configuration: Debug Win32 ------
1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl getPlayerChoice(enum Choices &)" (?getPlayerChoice@@YAXAAW4Choices@@@Z) referenced in function _main
1>C:\Users\Kyle\documents\visual studio 2012\Projects\ConsoleApplication15\Debug\ConsoleApplication15.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
非常感谢任何有关如何解决此问题的指导!
最佳答案
出现此问题是因为您的函数原型(prototype)与函数定义不同。您的原型(prototype)为:
void getPlayerChoice(Choices & choice);
但是你对该函数的定义是:
void getPlayerChoice(Choices playerChoice, int PChoice)
要解决此问题,函数原型(prototype)和定义必须相同。
关于c++ - 我不断收到错误 LNK2019,似乎无法弄清楚如何解决它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19986733/
我一直在试图理解人们一直在使用的这个网格系统。有时让我觉得自己很蠢。 我了解如果您使用无边距的 12 网格系统。第 12 列将是 100%,而第 1 列将约为 8.33333%。 我一直在看一些网格系
我们被分配了一个用于系统编程的 ASCII 压缩项目,但我在代码中的某一特定行上遇到了困难。 我问了question关于压缩,在处理完纸上示例文件的前十几个字母后,我将数组代码调整到了我的程序中。在
我正在使用 Appcelerator 框架编写应用程序,但偶尔会发生崩溃。我正在尝试找出导致崩溃的原因,因此我决定查看 iOS 模拟器崩溃报告。当然,这对我来说都是希腊语,但我希望得到一些指导,了解其
有人可以给我一些指导或指导我阅读有关 C++ set 对象的优秀教程吗? 我有一段这样的简单代码: #include using namespace std; int main() { ch
老实说,我不知道我的问题是否有解决方案,但我想在 Swift 中捕捉上下文切换发生的时间。 我正在想象一个需要很长时间才能完成的功能,例如远程服务器上的写操作,我在想是否有办法了解何时(至少在哪一行)
我正在使用 Yii2 并且一直在阅读 theming和 theme inheritance ;但是有一些问题: 考虑以下示例: 'view' => [ 'theme' => [
我尝试使用 AJAX 发布,因为我不想使用提交按钮并在每次单击它时重新加载页面。我正在使用此代码进行 ajax: Ajax loading error, please try again.").sho
我正在尝试找出将在 NodeJS 应用程序中使用的 MongoDB 模型的理想设计。该应用程序的设置类似于调查,某些步骤会根据之前的选择提供选项。这是选择和可能性的示例。 第 1 级:图案类型:纯色、
我有一个 API/Express 路由器: router.post("/signup", async function (req, res) { try { var user
我注意到 JFileChooser 隐藏了 Windows 系统文件。 hiberfil.sys、pagefile.sys、$Recycle.Bin 等文件、一些无法打开的快捷方式文件夹等... 我可
这是我第一次使用 Django,到目前为止,我对这个框架的工作方式印象深刻。我目前正在开发我的第一个应用程序,并正在处理数据库内容,但是,我在弄清楚如何在不运行原始查询的情况下进行内部联接时遇到问题。
我在自动调整蒙版大小方面遇到了一些问题。这是交易:我正在使用最近发布的 TwUI ,它从 UIKit 中获取了很多,但它在 Mac 上。这就是我为 iOS 和 Mac 标记的原因。因此,我创建了一个底
好吧,这是一个很长的,打起精神来! :) 最近我尝试在启动期间启动一个用 bash 编写的看门狗脚本。所以我在 rc.local 中添加了一行,其中包含以下内容: su someuser -c "/h
我在我的机器上安装了多个版本的 Windows 软件开发工具包,有趣的是,我的机器上已经安装了一个 Visual studio Installer工具的版本低于近一年前安装的版本: Windows S
widget('zii.widgets.CMenu', array( 'items'=>array( array('label'=>'Home', '
我是一名优秀的程序员,十分优秀!