Question: Having trouble fixing the error in my code checking the credentials to verify whether a person is an administrator or a user: Undefined symbols for
Having trouble fixing the error in my code checking the credentials to verify whether a person is an administrator or a user:
Undefined symbols for architecture x86_64: "Administrator::login(char const*, char const*)", referenced from: _main in main-dd2a50.o "User::login(char const*, char const*)", referenced from: _main in main-dd2a50.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Code:
Security.h
#include
#include
using namespace std;
enum credentials {invalid, user, administrator};
class Security{
public:
static enum credentials
validate(const char *userName, const char *password);
};
Security.cpp
#include
#include
#include "Security.h"
enum credentials
Security::validate(const char *userName, const char *password)
{
if ((strcmp(userName, "abbott") == 0) &&
(strcmp(password, "monday") == 0)) {
return(user);
}
if ((strcmp(userName, "costello") == 0) &&
(strcmp(password, "tuesday") == 0)) {
return(administrator);
}
return(invalid);
}
Administrator.h
#include
#include
#include "Security.h"
using namespace std;
class Administrator
{
public:
static bool login(const char *username, const char *password);
};
Administrator.cpp
#include
#include
#include "Administrator.h"
#include "Security.h"
using namespace std;
bool Administrator::login(const char *username, const char *password)
{
if(Security::validate(username,password)==2){
return true;
}
else{
return false;
}
}
User.h
#include
#include "Security.h"
using namespace std;
class User
{
public:
static bool login(const char *username, const char *password);
};
User.cpp
#include
#include
#include "Security.h"
#include "User.h"
using namespace std;
bool User::login(const char *username, const char *password)
{
if (Security::validate(username,password)==1){
return true;
}
else {
return false;
}
}
Main.cpp
#include
#include
using namespace std;
#include "Administrator.h"
#include "User.h"
#include "Security.h"
char *progName;
int
main(int argc, char *argv[])
{
char *userName;
char *password;
if ((progName = strrchr(argv[0], '/')) == NULL) {
progName = argv[0];
} else {
++progName;
}
if (argc < 3) {
cerr << "usage: " << progName << "
return(1);
}
userName = argv[1];
password = argv[2];
cout << "Checking as Administrator:"
<< ((Administrator::login(userName,
password) == true) ? "" : " not")
<< " valid ";
cout << "Checking as User:"
<< ((User::login(userName, password) == true) ? "" : " not")
<< " valid ";
return(0);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
