小编fsc*_*can的帖子

c ++ 11最佳参数传递

考虑这些类:

#include <iostream>
#include <string>

class A
{
    std::string test;
public:
    A (std::string t) : test(std::move(t)) {}
    A (const A & other) { *this = other; }
    A (A && other) { *this = std::move(other); }

    A & operator = (const A & other)
    {
        std::cerr<<"copying A"<<std::endl;
        test = other.test;
        return *this;
    }

    A & operator = (A && other)
    {
        std::cerr<<"move A"<<std::endl;
        test = other.test;
        return *this;
    }
};

class B
{
    A a;
public:   
    B (A && a) …
Run Code Online (Sandbox Code Playgroud)

c++ parameter-passing rvalue-reference c++11

8
推荐指数
1
解决办法
1065
查看次数

标签 统计

c++ ×1

c++11 ×1

parameter-passing ×1

rvalue-reference ×1