Search code examples
c++classtypesconstructordelegation

How do I use named constructors in C++ using constructor delegates?


Say I have a constructor and a delegated constructor

SomeClass(const std::string&& _name) : obj_needs_construction(100), name(_name) {}
SomeClass(const std::string& _name) : SomeClass(_name) {}

But both are using the same type, I've seen many solutions but they all seem to operate because they make different types but that won't work in my situation. How can I solve this?

Thanks.


Solution

  • SomeClass(const std::string& _name) : SomeClass(std::move(_name)) {}