Inherited constructor (using) and moving

UPDATE: this seems to be my mistake, I did not install CTP correctly. MS could not reproduce the error.

I would like to move a variable from a derived class to my base class (there are several classes between them)

I usually passed the const & argument, but I try to pass it by value and move it down the hierarchy, avoiding copying.

Here are my classes:

#include <string>

class base {
 public:
    explicit base(std::string url) : url_{std::move(url)} {}
    // prevent copy
    base(const base&) = delete;
    base& operator=(const base&) = delete;
    virtual ~base() {}

protected:
    std::string url_;
};

class derived : public base {
 public:
    using base::base;
};

class derived_final : public derived {
 public:
    using derived::derived;
    explicit derived_final(std::string url) :
        derived{std::move(url)}
    {
        // do some stuff
    }
};


int main() {
    derived_final df { "test" };
}

and magazine:

e:\project\test\main.cpp(25) : error C2664: 'derived::derived(const derived &)': cannot convert argument 1 from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'const derived &'
        Reason: cannot convert from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'const derived'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

I also tried adding a move constructor to the base, as well as op =.

But output_final tries to use the derived copy constructor with the std :: string parameter as the parameter when I try to port the url to the derivative in the final_final derived constructor.

Any ideas why this is happening? I am using msvc 2013 with CTP (to support "using").

: https://bitbucket.org/syl/c-11-inherited-constructor-and-move/src

+3
1

, MSVC. GCC .

0

All Articles