= getSomething()
CSomething *m_pSomthingImpl;
ISomething& getSomething()
{
return *m_pSomethingImpl;
}
if CSomethingImpl has some member variable,
the copy is not successfull leave _vptr with 0.
I though reference & is just an alias.
There is no need to copy data.
CMIIW.
getSomething().dismiss() <- it works.
but alias.dismiss() <- it doesnt.
Works for me without issues, can you provide the code that works unexpectedly? https://wandbox.org/permlink/dxz05G7Q3hgGmwgm
Because address of new object, luckyly the same. Therefore, Reference should not be used. *Alias is not set to another object yet. Sorry, just replied.
Do you have a code example where it breaks? To understand what you mean
ISomething& temporary = getSomething(case1); temporary = getSomething(case2); temporary.dismiss() There should be error on case2 temporary.dismiss(). But it is ok if just : getSomething(case1).dismiss(); getSomething(case2).dismiss();
We couldn't compile this, give us a complete program including the problem.
Thanks Sir. Been solved.
Could you say the solution? i really don't understand what is your problem with the references: https://t.me/c/1071392087/169968
Once initialized,reference cannot be changed to another object. https://en.cppreference.com/w/cpp/language/reference_initialization
Обсуждают сегодня