temporary object in function call

T

thucdat

Visual Studio C++ compiles the following:



class someclass {
//
};

void somefunction(someclass &) {
//
}

int main() {
somefunction(someclass());
return 0;
}



But Dev-C++ (Bloodshed) and g++ don't. I wonder if Visual Studio C++
is smarter here.
 
R

red floyd

Visual Studio C++ compiles the following:



class someclass {
//
};

void somefunction(someclass &) {
//
}

int main() {
somefunction(someclass());
return 0;
}



But Dev-C++ (Bloodshed) and g++ don't. I wonder if Visual Studio C++
is smarter here.

No, Bloodshed (which uses g++) and g++ are correct. You can't bind a
temporary to a non-const ref. If you turn of MS extensions (I think
it's /Za) VStudio will also properly generate an error.
 
J

Jim Langston

red said:
No, Bloodshed (which uses g++) and g++ are correct. You can't bind a
temporary to a non-const ref. If you turn of MS extensions (I think
it's /Za) VStudio will also properly generate an error.

Also setting warning levels to 4 in VStudio will produce a warning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,489
Latest member
BrigidaD91

Latest Threads

Top