jeudi 28 novembre 2019

Templated member function access in other CPP files [duplicate]

This question already has an answer here:

I have a header file where I have below declaration:

A.hpp

class A
{
public:
    template <typename T1 = void, typename T2 = void>
        T2 set(T1* saddr, T2& sddrlen) const;
}

In a A.cpp I have the below code:

A.cpp

#include "A.hpp"

template <typename T1, typename T2>
T2 A::set(T1* saddr, T2& sddrlen) const
{
}

Now in another CPP file I have code like below:

B.cpp

#include "B.hpp"
#include "A.hpp

void B::set(const A& a)
{
 int y,x;
 a.set<int,int>(&y,x)
}

But while compiling the code I am getting B.ccp unresolved reference to A::set .. though I am liming A.cpp. I tried adding below line in A.hpp

template int A::set<int, int>(int*, int&) const;

But it did not help.

How can I solve the issue?

Aucun commentaire:

Enregistrer un commentaire