【发布时间】:2019-07-24 05:10:28
【问题描述】:
我有以下两个类:
class A
{
public:
A() : value(false) {}
bool get() const
{
return value;
}
protected:
bool value;
};
class B : public A
{
public:
void set()
{
value = true;
}
};
现在我使用它们如下:
B* b = new B;
std::shared_ptr<A> a(b);
auto func = std::bind(&B::set, *b);
std::cout << a->get() << std::endl;
func();
std::cout << a->get() << std::endl;
我希望a->get() 在第二次调用时返回true,但func() 没有修改它的值。这是为什么呢?
【问题讨论】: