(函数)的多重定义
multiple definition of (Function)
我有 3 个具有不同主要功能的.cpp文件:所以我有这个错误:"enstart()"的多个定义(另一个文件中有相同的代码,但主函数称为"hunstart()"
所以,这是我的代码:
#include <iostream>
#include <stdlib.h>
using namespace std;
int enstart()
{
system("TITLE HUN Homeless Millionaire");
system("COLOR 0A");
start:
//VARLIB START
string prominput;
string workinput;
string job = "Car Washer";
string bck;
string input1;
string ver = "0.0.1";
string note = "The game is in a really early state, please ignore the bugs!";
string shopinput;
string admininput;
int money = 0;
int snk = 0;
int shirt = 0;
int jobmoney = 1;
//VARLIB END
cout << "Hello, Welcome to Homeless Millionaire!" << endl;
cout << "Game version: " <<ver << endl;
cout << "Note: " <<note << endl;
cout << "Your money: " <<money << endl;
cout << "Type in a command from below!" << endl;
cout << "Commands:" << endl;
cout << "Change-log" << endl;
cout << "Story" << endl;
cout << "Creator" << endl;
cout << "Work" << endl;
cout << "Shop" << endl;
input1 = "null";
cin >> input1;
if (input1 == "Story") // remove from here
{
goto Story;
}
else
{
if (input1 == "Creator")
{
goto Creator;
}
else
{
if (input1 == "Shop")
{
goto shop;
}
else
{
if (input1 == "Work")
{
goto work;
}
else
{
if (input1 == "Change-log")
{
goto chlog;
cout << string( 20, '/n' );
}
else
{
if (input1 == "adminpanel")
goto admin;
}
}
}
}
}
goto start;
Story:
system("CLS");
cout << "The game is about a 18 year old men who went debt." << endl;
cout << "What did you except?" << endl;
cout << "Type in back to continue" << endl;
cout << string( 21, 'n' );
bck = "null";
cin >> bck;
if (bck == "back")
{
goto start;
}
goto Story;
Creator:
system("CLS");
cout << "The game was made by: Killer Doge (C) Karsza Levente" << endl;
cout << "Co-Creator and Translator: TOMI8401 (C) Deli Bence" << endl;
cout << "Type in back to continue" << endl;
bck = "null";
cin >> bck;
if (bck == "back")
{
goto start;
}
goto start;
shop:
system("CLS");
cout << "Welcome to the shop!" << endl;
cout << "Your bank account: " <<money << endl;
cout << "How to buy: Write in the codes of the selected item!" << endl;
cout << " ITEM | PRICE | CODE " << endl;
cout << " Uniform | 10 $ | UNIF " << endl;
cout << " Sneakers | 25 $ | SNEK " << endl;
cout << " Trainers | 35 $ | TRAN " << endl;
cout << "Better Uniform| 50 $ | BUNI " << endl;
cout << " Shirt | 50 $ | SHRT " << endl;
cout << " Elegant Shoes| 65 $ | ESHO " << endl;
cout << " Cheap Phone | 85 $ | PHON " << endl;
shopinput = "null";
cin >> shopinput;
if (shopinput == "SNK")
{
money -= 25;
snk = 1;
goto succb;
}
else
{
if (shopinput == "SHRT")
{
money -= 50;
shirt = 1;
goto succb;
}
}
goto shop;
work:
system("CLS");
cout << "Your current job: " <<job << endl;
cout << "Your salary is: " <<jobmoney << endl;
cout << "Your money is: " <<money << endl;
cout << "Commands:" << endl;
cout << "Promote(BUGGY)" << endl;
cout << "Work" << endl;
cout << "Back" << endl;
cout << string( 18, 'n' );
workinput = "null";
cin >> workinput;
if (workinput == "Promote")
{
goto promote;
}
else
{
if (workinput == "Work")
{
money += jobmoney;
goto work;
}
}
cin.get();
goto start;
succb:
system("CLS");
cout << "You successfully bought this item!" << endl;
cout << "Your balance:" <<money << endl;
cout << "Type in back to continue!" << endl;
bck = "non";
cin >> bck;
if (bck == "back")
{
goto start;
}
goto start;
promote:
system("CLS");
cout << string( 20, '/n' );
cout << "Type in JobInfo for more information!" << endl;
cout << "Type in OK to try to get a promotion!" << endl;
//continue this
cin.get();
goto start;
stat:
system("CLS");
cout << "Your stats:" << endl;
cout << "SNK "<<snk << endl;
cout << "SHRT "<<shirt << endl;
cout << "JOB "<<job << endl;
cout << "MONEY "<<money << endl;
cout << "JOBMONEY "<<jobmoney << endl;
bck = "null";
cin >> bck;
if (bck == "back")
{
goto start;
}
goto stat;
chlog:
system("CLS");
cout << "CHLOGTARTALOM" << endl;
cout << "Type in back for main menu!" << endl;
bck = "null";
cin >> bck;
if (bck == "back")
{
goto start;
}
goto chlog;
admin:
system("CLS");
cout << "Admin panel:" << endl;
cout << "Type in your password!" << endl;
cin >> admininput;
if (admininput == "hmalphabranch")
{
goto adminpanel;
}
else
{
goto start;
}
adminpanel:
system("CLS");
cout << "You can't do nothing here" << endl;
}
当你对一个名为 enstart
的函数有多个定义时,你可以通过以下方式修复它
-
使用不同的名称,或
-
将它们放在不同名称的命名空间中。
顺便说一下,'/n'
并不表示换行符。它是一个多字节字符常量,具有实现定义的值。在需要换行符的位置写'n'
。
在其他新闻中:
-
对代码前面的标签的
goto
通常对应于循环。查找for
、while
和do
循环。 -
对以
goto
结尾的代码块的goto
通常对应于函数的调用。您已经知道如何定义简单的函数。只需使用它们而不是标记的代码块。 -
AStyle 等免费工具可以帮助您自动使用适当的缩进来格式化代码。许多编辑器也可以这样做。我使用 AStyle 来格式化问题中的代码。
相关文章:
- 在命名空间中定义函数还是限定函数
- 为什么在定义函数之前先声明它
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- 这个c++代码是如何在没有定义函数的情况下运行的
- 具有外部"c"和程序集的未定义函数
- 已定义函数时出现 G++ "未定义的引用"错误
- 将自定义函数传递到基抽象类中以延迟执行
- C++使用 rand 定义函数语法
- Arduino:在 loop() 和自定义函数中运行相同的代码时出现问题
- 将具有固定签名的自定义函数名称注入 CRTP
- 使用定义函数模板别名
- 是否可以使用单个定义定义函数的常量和常规版本?(使用模板,自动,decltype等)
- 在内联程序集中定义函数和从 C++ 调用时出现问题
- 在 Metal 着色器代码中,如何定义函数的 in/out 参数变量?
- 声明和定义函数静态会产生"undefined reference to function_name()"
- 朋友定义函数的名称空间是什么
- 介子 对用户定义函数的未定义引用
- 如何使用 "using" 关键字定义函数原型/签名
- 在 C 结构中定义C++函数