Undefined reference to error in c++ (using a singleton class)
<p>I've made a class named Client and the definition goes below in client.h:</p>

<pre><code>#ifndef __CLIENT_H__
#define __CLIENT_H__

#include &lt;string&gt;

using namespace std;

class Client {
public:
    Client(string n, string p) : name(n), password(p) {logged_in = true;}
    void set_name(string n, string p) {name=n; password=p; }
private:
    string name;
    string password;
    bool logged_in;
};

#endif
</code></pre>

<p>then I've inherited a singleton class from Client named Admin in admin.h:</p>

<pre><code>#ifndef __ADMIN_H__
#define __ADMIN_H__

#include "client.h"

using namespace std;

class Admin : public Client {
public:
    static Admin* get_admin(string n, string p)
    {
        if (Admin::n == 0)
            Admin::admin = new Admin(n, p);
        else
            Admin::admin-&gt;set_name(n, p);
        return Admin::admin;
    }
private:
    Admin(string n, string p) : Client(n, p) {Admin::n++;}
    static int n;
    static Admin* admin;
};

int Admin::n = 0;

#endif
</code></pre>

<p>and here is my main.cpp:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include "client.h"
#include "admin.h"

using namespace std;

int main()
{
    Admin* administrator = Admin::get_admin("ghamar", "utcom90");
}
</code></pre>

<p>and the problem is that when I want to compile main.cpp using g++ (g++ main.cpp), I get the following error:</p>

<pre><code>/tmp/cc15VnHc.o: In function `Admin::get_admin(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)':
main.cpp:(.text._ZN5Admin9get_adminESsSs[Admin::get_admin(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)]+0x5f): undefined reference to `Admin::admin'
main.cpp:(.text._ZN5Admin9get_adminESsSs[Admin::get_admin(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)]+0xa0): undefined reference to `Admin::admin'
main.cpp:(.text._ZN5Admin9get_adminESsSs[Admin::get_admin(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)]+0xd1): undefined reference to `Admin::admin'
</code></pre>

<p>the important part of the error says:</p>

<pre><code>undefined reference to 'Admin::admin'
</code></pre>

<p>Can anybody help me out with this? thanks a lot for your time.</p>
