jeudi 6 août 2015

receiving a parameter as reference in C++

I had a question. In this case, while receiving a parameter as reference, will the compiler dereference the whole object?

class A {
int a;
};

void fun(A &param) {
    // Play with param
}

int main() {
    A *obj = new A();
    fun(*obj); // Dereference the pointer and receive it as reference
}

So,

  1. Will the compiler dereference the object?

  2. How to verify whether the compiler is dereferencing or not?

Thanks

Chid

Aucun commentaire:

Enregistrer un commentaire