void test_rr(std::string const &lvalue)
	std::cout<<"this is lvalue"<<std::endl;

void test_rr(std::string &&lvalue)
	std::cout<<"this is rvalue"<<std::endl;

int main()
	test_rr("this is"); //will output "this is lvalue"
	std::cout<<"system pause"<<std::endl;

	return 0;

how could I treat "this is" as rvalue reference?
The easiest way I could think is

std::string temp = "this is"

compiler = msvc2010
os = win7 64bits

Edited by stereomatching: n/a

6 Years
Discussion Span
Last Post by stereomatching

Visual C++ 2010 doesn't support the current rules for rvalue references (specifically the allowance for implicit conversions). The way to do it presently in 2010 is by creating a temporary rvalue string object:

test_rr(std::string("this is"));

Visual C++ 2011 supposedly supports the current rvalue reference rules.


Thanks, maybe we have to wait for five years before most of the main stream
compilers could support c++11


Five years might be a little pessimistic. Though for Visual C++ you'll probably have to wait until the version after 2011 for more complete conformance[1]. GCC is the closest that I'm aware of presently, so if you want to play with C++11 you should hop over there.

[1] Some of the most anticipated features (eg. variadic templates) still aren't implemented because "it's difficult". :icon_rolleyes: On the plus side, this breeds confidence that the features will be solid when they're released.

Some of the most anticipated features (eg. variadic templates) still aren't implemented because "it's difficult"

This is one of the useful feature of c++11, we don't need to use some "horrible"
work around to mimic it again
I don't know how of those work around work
But I am pretty appreciate that I can use a simple way to do it

MS said it is almost finish

Edited by stereomatching: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.