2

When I added a move constructor to my child class, I found I can't use default arguments for the constructor. I've also tried using an overloaded constructor in base_class with zero arguments which calls the normal constructor with the arguments passed in manually but I'm having the same issue.

The error message from Visual Studio is: error C2512: 'child_class<base_class>': no appropriate default constructor available

class base_class {
public:
    base_class(int param1=1) {}
};

template <typename BaseType>
class child_class : public BaseType {
public:
    using BaseType::BaseType;
    child_class(child_class&& move_in)
        : BaseType(std::move(move_in)) {}
};

int main(int argc, char** argv) {
    child_class<base_class> instance1; // MSVC says no default constructor so doesn't compile.
    child_class<base_class> instance2(123); // No problem
}
4
  • 2
    You probably meant std::move(move_in). Commented Apr 5, 2018 at 16:55
  • What makes you think this has to do with the move constructor, rather than the inheriting constructor? Commented Apr 5, 2018 at 16:57
  • @SebastianRedl Yes, sorry. copy paste error. I'll fix that. Commented Apr 5, 2018 at 16:57
  • @NicolBolas The code compiles fine without the move constructor. Commented Apr 5, 2018 at 17:01

1 Answer 1

3

This is probably an MSVC bug in the inherited constructor implementation. Clang compiles the code without complaint.

Sign up to request clarification or add additional context in comments.

1 Comment

This is a bug without any doubt according to the definition of default initialize [dcl.init]/7

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.