小编Tod*_*ddR的帖子

移到L值参考中时,std :: move会导致切片吗?

请参见以下代码:

#include <iostream>
#include <chrono>

class Parent
{
public:
    Parent() = default;
    virtual ~Parent() = default;
    Parent(const Parent& pr) : i{pr.i} {std::cout << "Parent copy constructor\n";}
    Parent& operator=(const Parent& pr) {std::cout << "Parent copy assignment\n"; this->i = pr.i; return *this;}
    Parent(Parent&& pr) : i{std::move(pr.i)} {std::cout << "Parent move constructor\n";}
    Parent& operator=(Parent&& pr) {std::cout << "Parent move assignment\n"; this->i = std::move(pr.i); return *this;}

    virtual void print_i_j() = 0;

    int i = 10;
};

class Child : public Parent
{
public:
    Child() …
Run Code Online (Sandbox Code Playgroud)

c++ move-semantics object-slicing c++11

3
推荐指数
2
解决办法
128
查看次数

标签 统计

c++ ×1

c++11 ×1

move-semantics ×1

object-slicing ×1