功能已经具有字符串变量的主体和重新定义
function already has a body and redefinition of string variable
错误:错误消息
mainfun.cpp:
#include <iostream>
#include <string>
#include "userCheckFunH.h"
using namespace std;
int yesNo;
string passName;
string userName;
string userRetrieve()
{
if (userName == "")
{
cin >> userName;
}
else
{
if (userName == "devin772" || userName == "guestacc")
{
yesNo = 1;
}
else
{
yesNo = 0;
}
}
return userName;
}
int userCheck()
{
return yesNo;
}
int main()
{
do
{
string userN;
system("cls");
// ui
cout << " DH DB " << endl;
cout << "x----------------x" << endl;
//username
cout << "username: " << endl;
cout << "> ";
// fun call
userRetrieve();
int continueP = userCheck();
cout << "" << endl;
// password
if (continueP = 1 && userRetrieve() == "devin772")
{
cout << "password:" << endl;
cout << "> ";
cin >> passName;
if (passName == "12qwaszx")
{
cout << "" << endl;
system("pause");
system("cls");
// run program
dataBaseRunP("admin");
npOpen();
cout << "" << endl;
system("pause");
return 0;
}
}
else if (continueP = 1 && userRetrieve() == "guestacc")
{
cout << "password:" << endl;
cout << "> ";
cin >> passName;
if (passName == "guestguest")
{
cout << "" << endl;
system("pause");
system("cls");
// run program
dataBaseRunP("regUser");
npOpen();
cout << "" << endl;
system("pause");
return 0;
}
}
else
{
cout << "Invalid username." << endl;
cout << "" << endl;
system("pause");
userRetrieve() = "";
userName = "";
yesNo = 0;
passName = "";
}
} while (true);
system("pause");
}
nextfun.cpp:
#include <iostream>
#include "userCheckFunH.h"
using namespace std;
string userLevel;
int dataBaseRunP(string authLevel)
{
string fileName;
if (authLevel == "regUser")
{
fileName = "user.txt";
userLevel = fileName;
}
else if (authLevel == "admin")
{
fileName = "admin.txt";
userLevel = fileName;
}
else
{
cout << "ERROR - user level not found." << endl;
system("pause");
exit(EXIT_FAILURE);
return 0;
}
exit(EXIT_SUCCESS);
return 0;
}
void npOpen()
{
string fileNpName;
fileNpName = userLevel;
fileNpName = "notepad "" + fileNpName + """;
system(fileNpName.c_str());
}
userCheckfunh.h:
#ifndef USERCHECKFUN_H
#define USERCHECKFUN_H
#include "nextFun.cpp"
int dataBaseRunP();
void npOpen();
#endif
我正在尝试制作一个基本程序,该程序允许您在基本的C 程序中通过Windows打开文件。继续遇到此错误。尝试了不同的标头电具,可变名称,功能名称,文件名。我还删除了nextfun.cpp,并且程序运行良好。我无法克服此错误,请提供帮助。谢谢!:)
包括
在UserCheckfunh.h中使用的CPP文件是非常不寻常的#include "nextFun.cpp"
您的nextfun.cpp文件包含此标题:
#include "userCheckFunH.h"
由于您的CPP文件没有include guard(很好),因此您两次获得CPP文件中的功能。
不在标题中包含CPP文件。
相关文章:
- 定义C++新的环境变量并在 bat 文件中使用它
- 是否可以使用单个定义定义函数的常量和常规版本?(使用模板,自动,decltype等)
- 从使用概念定义的函数返回新对象
- 如何在C++中为 if 和 else 语句定义新行为
- 如何从 C++ 中的现有模板函数定义新函数
- 自定义分配器,包括放置新案例
- 正在通过const-ref未定义的行为捕获新构造的对象
- 如何在CPropertySheet中定义新颜色
- 谁定义新操作员
- 未定义的符号'fixed_address_empty_string':带有protobuf的新张量流运算
- 新的C ,未定义的参考
- boost :: fibonacci_heap:带有比较器重新定义圆形定义错误的嵌套定义
- 宏,用于定义带有添加前缀的新宏
- 取消脱壳:使用模板在多行类型定义中添加一个尖括号后的新行
- C 通过Typedef定义新类型
- 通过在此指针上放置新位置重新初始化对象时未定义的行为
- 在 ss.clear() 之后使用 ss.str( " ") 用于新定义的字符串流
- Eclipse CDT将方法定义定义到标头文件
- 是标头文件中使用“新”定义的成员指针泄漏
- LEX 程序中的未定义定义