mercredi 27 mai 2020

Is declaring a reference and passing it in the same as just passing by reference?

Say you have a function like this:

void func(int & arg) {
    std::cout << arg << std::endl;
}

Is doing something like:

int x = 10;
int & y = x;

func(y);

the same as:

int x = 10;

func(x)

Does arg become a int && arg or does it stay a int & arg when you pass in a pre-declared reference like the first case?

Aucun commentaire:

Enregistrer un commentaire