multiple definition of ..

login.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#ifndef LOGIN_H
#define	LOGIN_H
#include <iostream>

class login {

public:
   void addOrRemoveCashier(std::string role);
   
private:
     int input;
};

#endif	/* LOGIN_H */



login.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#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
                     //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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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 Login;
    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:
                       Login.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)
            {
               std::cout << "not found" <<std::endl;
            }
            if(found)
            {
                break;
            }
        }
    }
}


I am getting the error, multiple definition of addOrRemoveCashier(std::string)
using netbeans 7.4


Last edited on
It sounds like foo should just be doing add/minus, and the prompting stuff be done elsewhere.

Have you considered that the stuff in mainPage() belongs in main()?
if my mainPage() belongs to main, how am i suppose to make the user go back to the mainPage after the add() and minus() is done?
Why don't you rename foo to something meaningful, then it might be clearer where things should be done.

You don't see a file class asking for a file name, right? Something asks for a file name and that name is passed to the file class to use. Similarly, your class shouldn't have a method called mainPage. The prompting and stuff should be in main, not main calling into your class to ask for information.
I edited my post. please kindly take a look at the issue I am facing. thanks
Last edited on
> I am getting the error, multiple definition of addOrRemoveCashier(std::string)
no, your code doesn't compile so you can't have a linker error.
It didn't compile because login class didn't have int input;
and in my login.cpp I didn't #include <iostream> and #include <string>
I missed that out. I edited it already
Last edited on
line 11 login.cpp
std::cout <<"Select a choice!" std::endl;
should be std::cout <<"Select a choice!" << std::endl;

line 64 main.cpp
-
¿?

edit: so I don't think that that is your actual code
Last edited on
edited once again. sorry. as my original code was in my virtual box and it's running too slow just to open up a browser and going to web pages and I have to manually type this piece of codes I didn't realize there are some typos.

I am scanning through the codes that I manually typed again to check whether there is any more things i missed out

I edited to a simpler cout statement if the user is not found.

but that's not the point. the main thing is still, why am I getting the error
multiple definition of addOrRemoveCashier(std::string)
in netbeans and yet i can run it on my xcode and g++ it in my terminal
Last edited on
because your project is misconfigured, ¿can you show the build command that netbeans generates?
it may be linking `login.cpp' twice

also, the error message should be more explicit, indicating where the symbol was previously defined
Last edited on
Hi, I am not sure why my build becomes successful in netbeans now. maybe it's due to some unknown bugs in netbeans. should I encounter the problem once again I will flag out again.
Thanks for your time and patience and help
Topic archived. No new replies allowed.