mardi 13 avril 2021

Why C++ allows returning ifstream object?

In C++98, the following code does not compile because the ifstream has no copy constructor:

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

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

int main() {
    ifstream st= f();
}

However using multiple GCC versions with C++11, this compiles without warnings. What is the reason of this?

Aucun commentaire:

Enregistrer un commentaire