编译这段代码后 我收到错误消息,指出那里 发生双重删除;我的问题是到底是什么 此代码有误吗?问题出在哪里?
#include <iostream>
#include <memory>
class Manager;
class Interface {
protected:
friend class InputListener;
bool flag_;
};
class InputListener {
public:
InputListener(std::shared_ptr<Interface> manager_ptr) {
manager_ptr_ = std::move(manager_ptr);
std::async(std::launch::async,&InputListener::Run,this);
}
void Run() {
char c;
std::cin >> c;
manager_ptr_->flag_ = true;
}
private:
std::shared_ptr<Interface> manager_ptr_;
};
class Manager : public Interface {
public:
Manager()
: listener_ptr_{
std::make_unique<InputListener>(std::shared_ptr<Manager>(this))} {}
void Run() {
while (true) {
if (Interface::flag_)
break;
}
}
private:
std::unique_ptr<InputListener> listener_ptr_;
};
int main() {
Manager m;
m.Run();
return 0;
}
为什么此代码会产生此错误? munmap_chunk():无效的指针 中止(核心已弃用)