小编Ger*_*fer的帖子

为什么 C++ 允许返回 ifstream 对象?

在 C++98 中,以下代码无法编译,因为 ifstream 没有复制构造函数:

#include <iostream>
#include <fstream>
using namespace std;

ifstream f() {
    return ifstream("main.cpp");
}

int main() {
    ifstream st= f();
}
Run Code Online (Sandbox Code Playgroud)

但是,在 C++11 中使用多个 GCC 版本时,编译时不会发出警告。这是什么原因?

c++ fstream xvalue c++11

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

标签 统计

c++ ×1

c++11 ×1

fstream ×1

xvalue ×1