문제

I'm compiling in cygwin with gcc 4.8.2, and the compilation finishes without an error. But when linked, I receive the following message:

bin/libUsersMgmnt.a(CUsersMgmnt.cpp.o): In function nsUserMgmnt::CUsersMgmnt::CUsersMgmnt()': /home/HCAST2/v1.05-dev/UsersMgmnt/CUsersMgmnt.cpp:23: undefined reference toint nsMsgHandler::CMsgHandler::createLocationUserMap()' /home/HCAST2/v1.05-dev/UsersMgmnt/CUsersMgmnt.cpp:23:(.text+0x19f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `int nsMsgHandler::CMsgHandler::createLocationUserMap()' collect2: error: ld returned 1 exit status

I have this Base Class:

Header File CMsgHandler.h

namespace nsMsgHandler
{
    class CMsgHandler
    {
    protected:
        template<class enhFlags> createLocationUserMap();
    };
}

Code File CMsgHandler.cpp

... some code
using namespace nsMsgHandler;
... some code
template <class enhFlags>
int CMsgHandler::createLocationUserMap()
{
.....
}

This is the derived class: Header File CUsersMgmnt.h

namespace nsUserMgmnt
{
    class CUsersMgmnt : public CMsgHandler
    {
    public:
        CUsersMgmnt();
    };
}

Code file CUsersMgmnt.cpp

... some code
using namespace nsUserMgmnt;
... some code
CUsersMgmnt::CUsersMgmnt()
{
    this->createLocationUserMap<nsUserMgmnt::types::Class1>();
}

I'm pretty sure that there is an error in the code. I tried to resolve this problem for hours.

도움이 되었습니까?

해결책

You should move your:

template <class enhFlags>
int CMsgHandler::createLocationUserMap()
{
.....
}

to CMsgHandler.h

otherwise compiler is not able to instantiate your template in CUsersMgmnt.cpp

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top