Answer the question
In order to leave comments, you need to log in
How to get a reference to an object?
Hello!
I can not fully understand the work with passing objects by reference
Class A
{
B *_b;
C _c2;
C *_c;
A(){
B _b = new B();
C _c = new C();
_b->setC(*_c);
_b->setC(_c2);
}
}
Class B
{
C *_c;
void setC(const C& c){
_c = c;
}
}
Class C
{
}
ошибка: cannot convert 'const C' to 'C*' in assignment
Answer the question
In order to leave comments, you need to log in
Correctly:
No - a link is passed anyway. If you have a pointer and you want to pass a reference, then you must dereference the pointer.
Better not to bother with this issue. There are no references at the assembler level, so in fact the references are the same veiled pointers that have limited functionality at the compiler level for safer use.
The pointer is an integer. The size of a pointer does not depend on the type it points to, it depends only on the platform (in x64 pointers are 64 bits, and in x32 - 32 bits).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question