0

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

2 Answers 2

4

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
};
Sign up to request clarification or add additional context in comments.

Comments

0

You need:

using TControl<MeshLink*)>::

TControl;

This is because ctors are not inherited automatically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.