I have seen this error a lot, and there're a lot of questions about it here, but now I really don't know what to do.
User.h
#ifndef USER_H
#define USER_H
#endif // USER_H
#include <iostream>
using namespace std;
class User
{
private:
struct Accounts {string user, password, name;} accounts[2];
void setAccounts();
public:
int Access(string user, string password);
bool online;
User();
~User();
};
User.cpp
#include "User.h"
#include <iostream>
User::User() {/* data */}
User::~User() {/* data */}
void User::setAccounts()
{
accounts[0].user = "user01";
accounts[0].password = "pw01";
accounts[0].name = "hi";
accounts[1].user = "user02";
accounts[1].password = "pw02";
accounts[1].name = "hi2";
}
int User::Access(string user, string password)
{
unsigned short int i;
for (int i = 0; i <= 1; i++)
{
if (user.compare(this->accounts[i].user) == 0 and password.compare(this->accounts[i].password) == 0)
return 0;
}
return 1;
}
I've used even #pragma once
and it still not recognizing the class.
What do I do?
@edit: I moved down #endif // USER_H
and now the class has been recognized, but the constructor method still missed.
"error: multiple definitions of 'User::User()'"