0
我正在錯誤,addOrRemoveCashier的 多個定義(的std :: string)多個定義
用以下代碼,使用NetBeans 7.4
這是我
代碼
login.h
#ifndef LOGIN_H
#define LOGIN_H
#include <iostream>
class login {
public:
void addOrRemoveCashier(std::string role);
private:
};
#endif /* LOGIN_H */
login.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;
}
}
的main.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;
}
}
}
}
請給予建議和幫助的感謝
一個問題吧。另外,請提供一個SSCCE(sscce.org)。 – juanchopanza
好的我更感興趣的解決錯誤「多重定義addOrRemoveCashier(std :: string)」 – user3175729
0)聽起來像一個鏈接錯誤,但我不知道netbeans,所以我不能告訴你如何解決它 - 用兩個源文件嘗試一個* simpler *項目,然後建立起來。 1)使'登錄'一個單獨的功能,這將簡化很多事情。 2)參見1)。 – Beta