Код: Выделить всё
#include
#include
#include
class Child {
};
class Holder {
public:
Holder(std::shared_ptr child) : m_child {child} {
print_child_address();
}
std::shared_ptr get_child() {
return m_child;
}
void print_child_address() {
std::cout
Это работает с Python: < /p>
>>> from pointers import *
>>> c = Child()
>>> h = Holder(c)
0x607d93adc800
>>> hex(id(c))
'0x7c9f96460a70'
>>> hex(id(h.get_child()))
'0x7c9f96460a70'
< /code>
Однако, когда я называю это так, я получаю очень странный результат: < /p>
>>> h = Holder(Child())
0x6304fb8a8800
>>> hex(id(h.get_child()))
'0x7dd87bcc4eb0'
>>> hex(id(h.get_child()))
'0x7dd87bcc4c70'
>>> a = h.get_child()
>>> hex(id(h.get_child()))
'0x7dd87bcc4eb0'
>>> hex(id(h.get_child()))
'0x7dd87bcc4eb0'
Подробнее здесь: https://stackoverflow.com/questions/796 ... -via-pybin