-1

I have my base class:

class UnitTestThread : public testing::Test
{
    public:
        /// purgeQueue()
        template <typename T> void purgeQueue(const ___handle queue, T &data) const;
};

And my inheritance class:

class HmiTest : public UnitTestThread
{
    public:         
        // Sets up the test fixture.
        virtual void SetUp();
        // ...
}

void HmiTest::SetUp()
{
    // By default , purge all the queues
    CONTROL_ACTION_PARAM controlAction;
    purgeQueue(ApplicationContext.queueControlActionsToThermostat, controlAction);
}

And I have a link error:

HmiTest.obj : error LNK2019: unresolved external symbol "public: void __thiscall UnitTestThread::purgeQueue<struct CONTROL_ACTION_PARAM>(void * const,struct CONTROL_ACTION_PARAM &)const " (??$purgeQueue@UCONTROL_ACTION_PARAM@@@UnitTestThread@@QBEXQAXAAUCONTROL_ACTION_PARAM@@@Z) referenced in function "public: virtual void __thiscall HmiTest::SetUp(void)" (?SetUp@HmiTest@@UAEXXZ)

I don't understand why ... :-S

Thank you so much for your help guys !

Anthony
  • 325
  • 2
  • 5
  • 15

2 Answers2

3

You have declared the method, but you've not implemented it. Or if you have, it's in a cpp file, which is no good (needs to be in a header for a template method, or use explicit template instantiation).

You need to implement the method after the class definition:

class UnitTestThread : public testing::Test
{
    public:
        /// purgeQueue()
        template <typename T>
        void purgeQueue(const ___handle queue, T &data) const;
};

template <typename T>
void UnitTestThread::purgeQueue(const ___handle queue, T &data) const
{
    // Do something
}
Mark Ingram
  • 71,849
  • 51
  • 176
  • 230
  • I have implemented in my UnitTestThread.cpp file /// purgeQueue() template void UnitTestThread::purgeQueue(const ___handle queue, T &data) const { // ... } – Anthony Jan 13 '14 at 12:23
  • @Anthony as he said, your template needs to be defined in the the header file, not the .cpp file. – Simple Jan 13 '14 at 12:42
  • Or use explicit template instantiation if you know exactly which types you'll be working with. – Mark Ingram Jan 13 '14 at 13:21
2

Template implementation should be included in the header (.h) file

Raul Andres
  • 3,766
  • 15
  • 24