gpt4 book ai didi

c++ - 类函数的多重定义

转载 作者:行者123 更新时间:2023-11-28 07:10:12 25 4
gpt4 key购买 nike

我收到错误, addOrRemoveCashier(std::string) 的多重定义

使用以下代码,使用netbeans 7.4

这是我的

代码

登录.h

#ifndef LOGIN_H
#define LOGIN_H
#include <iostream>

class login {

public:
void addOrRemoveCashier(std::string role);

private:

};

#endif /* LOGIN_H */

登录.cpp

#include <sstream>
#include <fstream>
#include "login.h"

void login::addOrRemoveCashier(std::string role)
{
if (role == "Administrator")
{
std::cout << " " << std::endl;
std::cout <<"Select a choice!" std::endl;
std::cout << "1) Add New Cashier" <<std::endl;
std::cout << "2) Remove Existing Cashier" << std::endl;
std::cout << "3) Back" << std::endl;
std::cin >> input;
switch ( input )
{
case 1:
//add a cashier
//go back to the system Main menu after adding a cashier
break;
case 2:
//remove a cashier
//go back to the system Main menu after removing a cashier

break;
case 3:

break;
default:
std::cout << "Invalid choice!" << std::endl;
break;
std::cin.get();
}
}
else
{
std::cout << "You don't have access rights" << std::endl;
}
}

主要.cpp

#include <iostream>
#include <string>
#include <fstream>
#include "login.h"

inline char caesarDecrypt( char c )
{
if( isalpha(c) )
{
c = toupper(c);
c = (((c+65)-3) % 26) + 65;
}
return c;
}

int main()
{
int attempt = 3;
bool found = false;
int input;
login doAdministration;
std::string line,userName,password,output,userNameInFile,passwordInFile,roleInFile,role;
std::cout <<"----------------------------------"<< std::endl;
std::cout << "Login Page!" << std::endl;
while(attempt)
{
if(attempt != 0)
{
std::ifstream readFile("userandPassword.txt");
std::cout << "Enter UserName: ";
std::cin >> userName;
std::cout << "Enter Password: ";
std::cin >> password;
while (readFile >> userNameInFile >> passwordInFile >> role)
{
output = "";
for(int x = 0; x < passwordInFile.length(); x++)
{
output += caesarDecrypt(passwordInFile[x]);
}
if (userName == userNameInFile && password == output)
{
role = roleInFile;
std::cout << role << std::endl;
std::cout << "Login Successfully!"<< std::endl;
found = true;

std::cout << " " << std::endl;
std::cout <<"Welcome to System Main Menu!"<< std::endl;
std::cout << "1) Administration-Add/Remove Cashier" << std::endl;
std::cout << "2) Logout" << std::endl;

std::cout << "\nEnter your choice" << std::endl;
std::cin >> input;

switch ( input ) {
case 1:
doAdministration.addOrRemoveCashier(role);
break;
case 2:
go back to the Login page;
break;
-
default:
std::cout << "Invalid choice!" << std::endl;
break;
std::cin.get();
}
break;

}
}
if (!found)
{
attempt -= 1;
std::cout << "InValid UserName Or Password"<< std::endl;
std::cout << "Attempts Left: " << attempt<<std::endl;
if(attempt == 0) {
std::cout <<"System LOCKED!";
}
}
if(found)
{
break;
}
}
}
}

请多多指教和帮助谢谢

最佳答案

您甚至尝试过编译 login.cpp 吗?以防万一,您应该已经看到类似这样的错误:

std::cout <<"Select a choice!" std::endl;

(缺少<<)

关于c++ - 类函数的多重定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21119919/

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