jeudi 30 août 2018

what is the difference between &, *, && in c++ 11

I noted that in C++, there are several way to pass a variable to a function, here is a list:

struct A
{ 
   int a;
   void test()
   {
      std::cout<<"this is a test:"<<a<<std::endl
   }
}

void f0(A p)
{ 
    p.a=0;
    p.test();
}
void f1(A *p)
{
    p->a=1;
    p->test();
}

void f2(A &p)
{
    p->a=2;
    p->test();
}
void f3(A &&p)
{
    p->a=3;
    p->test();
}

what is the difference? I know about f0, f1 and f2 and present them here for completes.

What is the signification of f3 and how I can use it?

Aucun commentaire:

Enregistrer un commentaire