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;
	std::cin.get();

	return 0;
}

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

std::string temp = "this is"
test_rr(std::move(temp));

compiler = msvc2010
os = win7 64bits

I am completely unable to understand what you wants to do ?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.