some problem about move semantics

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,all, I have code as below:

void check(int & val)
{
	std::cout << "int &\n";
}

void check(int && val)
{
	std::cout << "int &&\n";
}

template <typename T>
void print (T && val)
{
	check (std::forward<T>(val));
}

int main()
{
	int x = 0;
	print (x);
	print (std::move (x));
}

I have some problems:

A、when call print (std::move (x)), the compiler will deduction print to
	Void print (int && val)
	
	So val is a rvalue reference, so check (int && val) should be
invoked, but actually not, why? Function forward just do a static_cast here,
its result also make val a rvalue reference?






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux