类函数的多重定义

时间:2014-01-14 17:26:10

标签: c++

我收到错误,       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;
            }
        }
    }
}

请提供建议和帮助谢谢

1 个答案:

答案 0 :(得分:1)

你有没有尝试编译login.cpp? 万一,你应该看到像这样的错误:

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

(缺少&lt;&lt;)