some problem about move semantics
叶佑群
yeyouqun@163.com
Mon Mar 25 05:06:00 GMT 2019
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?
More information about the Gcc-help
mailing list