c++ - Returning local object of a primitive type and a struct -


getting reference temporary variable:

struct s {     s() = default;     s(const s& other) = delete;     s(s&& other) = delete;      ~s(){} };  s foo1() {     return {}; // rvo (???) }  int foo2() {     return 42; // rvo }  int main() {     s& = foo1(); // compiles!     int& i2 = foo3(); // error c2440: 'initializing' : cannot convert 'int' 'int &' } 

i know reference life extension const specifier. , it's clear why foo2 gives error. why foo1 works?

p.s.: tested vs2013/15

compiling warnings enabled (/wall), incidentally following:

source_file.cpp(22): warning c4239: nonstandard extension used: 'initializing': conversion 's' 's &'


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -