C++ Logo

sg12

Advanced search

Re: [ub] Non-virtual destructor call

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 13 Dec 2013 17:15:59 +0200
On 13 December 2013 14:56, Andrzej Krzemienski <akrzemi1_at_[hidden]> wrote:
> template <typename T>
> struct Callback : std::function<void(T)>
> {
> Callback() : std::function<void(T)> { [](T){/*ignore*/} } {}
> };
>
> I can pass it by value, convert to std::function without slicing, and it
> looks it would be safe to do this:
>
> std::function<void(T)> * fun = new Callback;
> delete fun;


Why don't you do
std::function<void(T)>*fun = new std::function<void(T)>(Callback{});
delete fun;
instead? Apply auto* where necessary.

Received on 2013-12-13 16:16:00