填空题

移动构造函数

发布于 2022-03-03 17:17:51

为类A实现默认构造函数,以std::string为参数的构造函数,移动构造函数(move constructor),重载移动赋值操作符(operator=),析构函数,同时禁止该类进行复制构造(copy constructor),使得以下代码能够运行通过:


#include <iostream>
#include <string>

class A {
public:
    std::string s() const {
        return *_s
    }
private:
    std::string *_s
}

int main() {
    std::string input
    std::cin >> input
    A a(input)
    A b(std::move(a))
    std::cout << b.s() << std::endl
    A c
    c = std::move(b)
    std::cout << c.s() << std::endl
    return 0
} 输入描述: 一行字符串输入样例: abcd 输出描述: 两行字符串输出样例 abcd abcd
关注者
0
被浏览
3
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看