Why is the constructor F (F &) called instead of the constructor F (F &) in the constructor of class G?
f lvalue. , rvalue, - rvalue f, . lvalue. , .
lvalue , lvalue. , :
class G {
F f_;
public:
G(F&& f) : f_(std::move(f)) {
std::cout << "G()" << std::endl;
}
};
std::forward<>(), , f :
class G {
F f_;
public:
G(F&& f) : f_(std::forward<F>(f)) {
std::cout << "G()" << std::endl;
}
};
, lvalues rvalues f f:
class G {
F f_;
public:
template<typename F>
G(F&& f) : f_(std::forward<F>(f)) {
std::cout << "G()" << std::endl;
}
};
, , G :
F f;
G g(f);
: -, , , :
class G {
F f_;
public:
template<typename F>
G(F&& f) : f_(std::forward<F>(f)) {
std::cout << "G()" << std::endl;
}
G(G const&) = default;
G(G&);
};
G::G(G&) = default;
, , , , G G. , , . .