0

As I know, perfect forwarding is design for reducing the need of
many overloaded functions when you pass the reference to the function
and pass those reference to another functions

Besides, to fullfill the objective of perfect forwarding
&& should be able to swallow the lvalue and rvalue
That means I could write something like this

void accept(int const& a, int const& b) {}
void accept(int& a, int& b) {}
void accept(int const& a, int& b) {}
void accept(int& a, int const& b) {}
void testPF(int&& a, int&& b) {}

int main()
{ 
 testPF(2, 3);//ok
 int a = 10, b = 20;
 testPF(a, b);//error
}

error message
error: cannot bind 'int' lvalue to 'int&&'

my compilers : tdm gcc4.5.2
my os : windows xp sp3(32)

Thanks a lot

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by stereomatching
0

So the instructions of MSDN is wrong(although it is not a standard at all)?
And according to my understanding, I can't gain benefit from POD with rvalue reference

#include<vector>

struct Point
{
  int x;
  int y;  
};

int main()
{
  std::vector<Point> temp;
  Point A;
  A.x = 100; A.y = 200;
  temp.push_back(A);
  temp.push_back(std::move(A));//can't take any advantage
}

Am I right?Thanks a lot

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.