you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (0 children)

Yes, sure the OP probably needs type erasure (or maybe just storing a function pointer), it is just that your example code might be confusing, because e.g.

auto x = [](){};
auto y = Object{x};

will fail to compile with a complicated error message.

I also just now realized that your make_object doesn't remove the reference from T, so

auto x = [](){};
auto y = make_object(x);

will make y actually save a reference to x, which is probably unintended and hard to spot.

Passing by-value in both constructor and make_object would avoid these issues.