2

Given this code:

int& some_class::ret_ref(){
    return this->some_integer;
}
int* some_class::ret_ptr(){
    return &(this->some_integer);
}

int main(){
    some_class c;
    auto p=c.ret_ptr();
    auto r=c.ret_ref();
}

At compile time:

  • p is int*
  • r is int

Why was auto deduced as int* in p and it was not deduced as int& in r?

What is the rule here?

Humam Helfawi
  • 18,595
  • 13
  • 73
  • 147

0 Answers0