Note the example in reported might be over-simplified. If it is not oversimplified, then upgrading the Derived class so that:
Event(const Object* object) {
TRef ref(object);
for(int i = 0; i < 25; i++) {
charges_.emplace_back(ref);
}
works would solve the problem (i.e. adding a constructor in Derived
that take a TRef as an argument.
Cheers,
Philippe.
PS. Or even further
threads.emplace_back([object = std::move(object)]() {
TRef ref(object.get());
for(int i = 0; i < 100; i++) {
Event event{ref};
event.run();
}
});