- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是C++的新手,正在编写一个简单的角色扮演采矿游戏。我只编码了几周,但遇到了一个错误,该错误已经处理了好几天,但仍然没有解决任何问题。我什至考虑过只是取消程序然后重试。我有4个文件:Game.cpp,header.h,nuggetsFound.cpp和days.cpp。我试图拥有一个可以在整个文件中更改的全局变量,但是,即使我什至没有重新定义什么内容,我仍然会遇到这个疯狂的错误,提示“float percentOfOres”(?percentOfOres @@ 3MA)已经在Days.obj中定义。其中所有我的变量和文件都会 pop 其中的几个,而且我快要疯了。我只有13岁,所以我不能总是得到我需要的所有帮助,所以如果你们能帮助我,我将非常感谢。谢谢! (我排除了nuggetsFound.cpp,因为它与days.cpp的情况基本相同。game.cpp中还有很多代码,但我只包含了我认为相关的代码。这是两个文件
game.cpp
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include "Header.h"
using namespace std;
float netWorth{ 0.0 };
float salary{ 0.0 };
float percentOfOres{ 0.0 };
int main()
{
cout << "Welcome to Miner Man!\n";
cout << "Press any key and press enter to continue";days.cpp
#include "game.cpp"
using namespace std;
void days()
{
for (int iii{ 1 }; iii <= 5; iii++)
{
cout << "Net Worth: " << netWorth << "\tSalary: " << salary <<
"\tPercent of Ores: " << percentOfOres;
cout << "\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
cout << "CCCCCCCCCCCCC\n";
cout << "CCCCCCCC\n";
cout << "CCCC ///////\n";
cout << "CCC |O O |\n";
cout << "CC | __ |\n";
cout << "C asssssssa\n";
cout << "C a sssssss a\n";
cout << "C a sssssss a\n";
cout << " a sssssss a\n";
cout << "C h sssssss a\n";
cout << "C p h sssssss \n";
cout << "C p h l l\n";
cout << "CC p h p l l\n";
cout << "CCC p p p p___l l___\n";
cout << "CCCCC L___l l___l\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
Sleep(500);
system("cls");
cout << "Net Worth: " << netWorth << "\tSalary: " << salary <<
"\tPercent of Ores: " << percentOfOres;
cout << "\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
cout << "CCCCCCCCCCCCC\n";
cout << "CCCCCCCC\n";
cout << "CCCC p ///////\n";
cout << "CCC p |O O |\n";
cout << "CC p | __ |\n";
cout << "C phhhhhhaaaa sssssssa\n";
cout << "C p sssssss a\n";
cout << "C p sssssss a\n";
cout << "C p sssssss a\n";
cout << "C sssssss a\n";
cout << "C sssssss \n";
cout << "C l l\n";
cout << "CC l l\n";
cout << "CCC ___l l___\n";
cout << "CCCCC L___l l___l\n";
cout << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n";
Sleep(500);
system("cls");
}
}
#pragma once
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include "data.hpp"
using namespace std;
void days();
void endOfDayNugs();
void endOfDayNugs()
{
srand((unsigned)time(0));
int silverFoundToday = rand() % 25;
srand((unsigned)time(0));
int goldFoundToday = rand() % 10;
srand((unsigned)time(0));
int diamondsFoundToday = rand() % 5;
if (silverFoundToday == 0)
{
cout << "Sorry, you found no Silver today\n";
Sleep(3000);
system("cls");
}
else if (silverFoundToday > 0)
{
for (int sss{ 1 }; sss < 3; sss++)
{
cout << "You found " << silverFoundToday << " silver!\n";
cout << "\n/SSSSSS\\\n";
Sleep(500);
system("cls");
}
if (percentOfOres == 0)
{
cout << "You don't make any money of your silver yet, but continue working towards that promotion!";
Sleep(5000);
system("cls");
}
else if (percentOfOres > 0)
{
cout << "You made " << percentOfOres * silverFoundToday << "dollers off of your silver\n";
netWorth += percentOfOres * silverFoundToday;
Sleep(5000);
system("cls");
}
}
if (goldFoundToday == 0)
{
cout << "Sorry, you found no gold today\n";
Sleep(3000);
system("cls");
}
else if (goldFoundToday > 0)
{
for (int ggg{ 1 }; ggg < 3; ggg++)
{
cout << "You found " << goldFoundToday << " gold!\n";
cout << "\n/GGGGGG\\\n";
Sleep(500);
system("cls");
}
if (percentOfOres == 0)
{
cout << "You don't make any money of your gold yet, but continue working towards that promotion!";
Sleep(5000);
system("cls");
}
else if (percentOfOres > 0)
{
cout << "You made " << percentOfOres * goldFoundToday << "dollers off of your gold\n";
netWorth += percentOfOres * goldFoundToday;
Sleep(5000);
system("cls");
}
}
if (diamondsFoundToday == 0)
{
cout << "Sorry, you found no diamonds today\n";
Sleep(3000);
system("cls");
}
else if (diamondsFoundToday > 0)
{
for (int ddd{ 1 }; ddd < 3; ddd++)
{
cout << "You found " << diamondsFoundToday << " diamonds!\n";
cout << "\n/DDDDDD\\\n";
Sleep(500);
system("cls");
}
if (percentOfOres == 0)
{
cout << "You don't make any money of your diamonds yet, but continue working towards that promotion!";
Sleep(5000);
system("cls");
}
else if (percentOfOres > 0)
{
cout << "You made " << percentOfOres * diamondsFoundToday << "dollers off of your diamonds\n";
netWorth += percentOfOres * diamondsFoundToday;
Sleep(5000);
system("cls");
}
}
最佳答案
void foo(); // function declaration
extern float bar; // variable declaration
void foo() { } // function definition
float bar; // global variable definition
static float widget; // local variable definition
extern float netWorth;
extern float salary;
extern float percentOfOres;
float netWorth{ 0.0 };
float salary{ 0.0 };
float percentOfOres{ 0.0 };
static
。这些变量被认为是该编译单元的隐藏实现细节,在外部将不可见。
static float foo;
而不违反一定义规则。但是,请注意,每个文件的
foo
都引用不同的变量!
inline
的函数可能存在于多个编译单元中,链接器将选择其中一个,而丢弃其他一个。
关于c++ - 在Days.obj中已经定义了奇怪的错误 “float percentOfOres”(?percentOfOres @@ 3MA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61349750/
一段时间以来,我一直在做这个反复出现的噩梦(阅读 - 我的应用程序中的错误)。出于某种原因,某个计时器在我停止后继续发送“Elapsed”事件,即使 在事件本身 计时器“承认”已被禁用!检查一下: /
为了找到 2 个 git 分支的共同祖先,需要做的是: git merge-base branch another_branch 好的。但是……如果两个分支都已经 merge 了怎么办?当我在这种情况
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 1年前关闭。 Improve this
我想要一个相机 View ,可以将图像捕获到本地文件或让用户从本地照片库中选择图像。我想也许有人为此编写了很好的库/代码。也许我可以利用它。已经有好的了吗?谢谢。我只是避免重新发明轮子:) 最佳答案
我从 master 分支创建了一个功能分支。之后有来自功能分支的提交 [F1]。 [F1] -- Feature Branch / [M1]-[M2
我喜欢使用 .NET 进行编程,尤其是 C# 3.0、.NET 3.5 和 WPF。但我特别喜欢的是 Mono .NET 确实与平台无关。 现在我听说了 Mono 中的 Olive 项目。我找不到某种
介绍和搜索 所以我认为我犯了一个严重的错误,我很担心。我已经分析了独立负责人的论坛,我已经接近找到答案,但场景太具体,不适用于我所在的位置。如果您找到可以回答我的问题的特定主题,请链接我。 例如:Ho
我有一个类似于下图的提交图。标记为 * 的提交表示大量提交。 A* | B--------- | | C* D* master 和 cor
我喜欢使用 .NET 进行编程,尤其是 C# 3.0、.NET 3.5 和 WPF。但我特别喜欢的是 Mono .NET 确实与平台无关。 现在我听说了 Mono 中的 Olive 项目。我找不到某种
我们最近接手了一个 .NET 项目,在查看 db 后,我们在某些列中有以下内容: 1)某些列具有诸如" & etc etc 2) 有些有 标签和其他非 html 编码的标签 这些数据
你好,当我导航到应用程序中的另一个页面时出现此错误 我不知道为什么这个错误出现 #0 _AsyncCompleter.complete (dart:async/future_impl.da
我使用以下 C 算法计算数据的 CRC32: #define CRC32_POLYNOM_REVERSED 0xEDB88320 uint32 calcCrc32(uint8* buffer, u
我试图在我的一个测试中断言模型中的字段没有改变。我知道从哲学上这是不正确的,但由于我控制了我需要知道的所有变量,所以我只想检查我的数据库条目是否没有改变。 我愿意接受一个解决方案,该解决方案可以将其转
我是 GitHub 的新手。并通过 Eclipse 使用它我们是两个人在开发一个应用程序。当我在 Git shell 中检查 git status 时,我得到以下状态。 On branch maste
简单代码: std::ifstream file("file.txt"); std::string line; while(getline(file,line)) ; //exhaust file
是的,我又找不到这个 Gradle DSL 方法:'compile()' 问题。 我检查了我有: buildscript { repositories { jcenter()
HTML: articles CSS: #main_menu { float: left; padding-top: 10px; vertical-align: m
我是一名优秀的程序员,十分优秀!