Hi, LeafyCircuits here.
Comp Specs:
OS: Windows 7 Home Premium 64-bit
Compiler: GNU gcc compiler with ISO and STL
IDE: Dev C++ v4.9.9.2 using C++11
NOTE: Code posted represents a portion of the project file. Assume that I know that all other code in the file works. Problem lines are commented for your convenience; if there are no "problem lines", assume that the code itself compiles.
I'm making an experimental "User" class and handlers, and I'm encountering an issue I haven't seen before. Below is the class `User' and a class `UserHandler' that handles function relating to the User classes, and a main that tests one of the functions of UserHandler.
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
|
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "core.h"
using namespace std;
using namespace AS_C;
class User
{
public:
User(string aname, string apass)
{
name=new string;
password=new string;
(*name)=aname;
(*password)=apass;
}
string getName() {return *name;}
private:
string getPass() {return *password;}
void changeName(string newname) {*name=newname;}
void changePass(string newpass) {*password=newpass;}
string *name, *password;
};
static class UserHandler
{
public:
friend class User;
void addUser(string thename, string thepass)
{
userbin[thename]=new User(thename, thepass);
}
void deleteUser(string thename)
{
delete userbin[thename];
userbin[thename]=0;
userbin.erase(thename);
}
private:
static map<string, User*> userbin;
}u_hnd;
main()
{
u_hnd;
u_hnd.addUser("Benny", "lolpass");
}
|
The code itself compiles, but the Linker spews an error, which prevents full compilation. Here's the error I get:
In function `ZNSt6vectorISsSaISsEE20_M_allocate_and_copyIN9__gnu_cxx17__normal_iteratorIPKSsS1_EEEEPSsjT_S9_':
[Linker error] undefined reference to `UserHandler::userbin'
|
According to the compile log, that long function is somewhere in a temporary .o in my comp's ...\appdata\local\temp\ directory, but... why are my .o's being created in the temp file directories? Shouldn't they be created in the working directory? Any assistance with this problem would be very helpful, thanks.
I'm new to the forums, to constructive criticism is greatly appreciated.