I've been struggling with this issue for a while and can't seem to get it right with all the templates and specializations. I think I'm missing a definition of the static function internal_set_BC
but I'm not sure. When I compile the code below, I get the following error:
test.cc:37:49: error: invalid use of incomplete type ‘class RT<2, D>’
static void RT<2, D>::internal_set_BC(D& d, T& t)
^
test.cc:19:7: error: declaration of ‘class RT<2, D>’
class RT: public BC<n, D>
^
test.cc:41:49: error: invalid use of incomplete type ‘class RT<3, D>’
static void RT<3, D>::internal_set_BC(D& d, T& t)
^
test.cc:19:7: error: declaration of ‘class RT<3, D>’
class RT: public BC<n, D>
The simplified code is as follows:
class A {};
class B {};
class C {};
class E {};
template <int n>
class Base
{};
template <int n, typename D>
class BC: public Base<n>
{
public:
virtual void set_BC(D& d, A& a) =0;
virtual void set_BC(D& d, B& b) =0;
};
template <int n, typename D>
class RT: public BC<n, D>
{
public:
void set_BC(D& d, A& a)
{internal_set_BC(d, a);}
void set_BC(D& d, B& b)
{internal_set_BC(d, b);}
private:
template <typename T>
static void internal_set_BC(D& d, T& t);
};
template <typename D, typename T>
static void RT<2, D>::internal_set_BC(D& d, T& t)
{//code
}
template <typename D, typename T>
static void RT<3, D>::internal_set_BC(D& d, T& t)
{//code
}
Moreover, when I try to instantiate internal_set_BC
with this code:
template void RT<2, C>::internal_set_BC(C& d, A& t);
I get this error:
test.cc:45:51: error: explicit instantiation of ‘static void RT<n, D>::internal_set_BC(D&, T&) [with T = A; int n = 2; D = C]’ but no definition available [-fpermissive]
template void RT<2, C>::internal_set_BC(C& d, A& t);
Which supports my suspicion of a missing definition I had on the above code.
Your help is highly appriciated.