Reputation: 107
I try to inherit from the class template "TControl" but the derived class "TControlML" does not see the constructor of the base class. I have read related articles but still do not see the cause. I have made a minimal example:
using namespace std;
class MeshLink
{
};
template<typename WU_TYPE>
class TControl
{
public:
TControl(std::vector<WU_TYPE>& vWorkunits_):
sTodo(vWorkunits_.begin(),vWorkunits_.end())
{}
std::set<WU_TYPE> sTodo;
};
class TControlML:public TControl<MeshLink*>
{
public:
};
int main()
{
vector<MeshLink*> vMeshLinks;
TControl<MeshLink*> ctrl(vMeshLinks); // Good
TControlML ctrl2(vMeshLinks); // Fails
}
GCC says:
test.cpp:35:29: error: no matching function for call to ‘TControlML::TControlML(std::vector<MeshLink*, std::allocator<MeshLink*> >&)’
TControlML ctrl2(vMeshLinks); // Fails
Upvotes: 0
Views: 30
Reputation: 10880
You need:
using TControl<MeshLink*)>::
TControl;
This is because ctors are not inherited automatically.
Upvotes: 0
Reputation: 217085
You have to use base constructor, you might use using
for that
class TControlML:public TControl<MeshLink*>
{
public:
using TControl::TControl;
};
Or the old way:
class TControlML:public TControl<MeshLink*>
{
public:
TControlML(std::vector<WU_TYPE>& vWorkunits_):TControl(vWorkunits_) {}
// Same for each constructor
};
Upvotes: 4