Unresolved external symbol error LNK2019

77 views Asked by At

I am very new to C++ and after I wrote some kind of smart pointer I've got the following error: Error 1 error LNK2019: unresolved external symbol "public: __thiscall RC::RC(void)" (??0RC@@QAE@XZ) referenced in function _main I've read that is because it can't find some external source. But I don't use any external source the code below is in one single file. How is it possible to fix this error message?

My code:

#include <iostream>

using namespace std;

class RC
{
    private:
    int count; // Reference count

    public:
    RC();

    int incRefCnt()
    {
        count++;
        return count;
    }

    int decRefCnt()
    {
        return --count;
    }
};


template < class T > class my_pointer
{
    private:

    T* reference;       /** pointer */

    public:

    my_pointer();

    my_pointer(T* reference)
    {
        reference->incRefCnt();
    }

    my_pointer(const my_pointer<T>& sp) : reference(sp.reference)
    {
        reference->incRefCnt();
    }

    ~my_pointer()
    {
        if (reference->decRefCnt() == 0)
        {
            delete reference;
        }
    }

    T& operator* ()
    {
        return *reference;
    }

    T* operator-> ()
    {
        return reference;
    }

    my_pointer<T>& operator = (const my_pointer<T>& sp)
    {
        if (this != &sp) 
        {
            if (reference->decRefCnt() == 0)
            {
                delete reference;
            }

            reference = sp.reference;
            reference->incRefCnt();
        }

        return *this;
    }
};

void main()
{
    my_pointer<RC> obj1 = new RC();
    my_pointer<RC> obj2 = obj1;
}
0

There are 0 answers