Following is a minimal example code producing the link error: (all in the same file)
class A is only declared
class A{
public:
A();
~A();
};
class B has A as member
class B{
public:
B(){};
~B(){};
A a;
};
following class is to be used as a template base class
template<class T>
class base{
public:
base(){};
~base(){};
virtual operator T() = 0;
};
class child : public base<B>{
public:
child(){};
~child(){};
operator B()
{
B o;
return o;
}
};
main:
int main(){
child obj;
return 0;
}
On compiling the code, I get the following link error:
in function `B::B()':
undefined reference to `A::A()'
undefined reference to `A::~A()'
error: ld returned 1 exit status
My question is, if the conversion operator is not being called in the code, why the link error? Also what can be a workaround, I would still like the operator to be virtual but don't have A's definition.