c++ - initialize struct with shared_ptr<void> -
i maintain running error no matching constructor initialization of 'std::shared_ptr<void>'
makes sense, don't know begin.
here i'm working with.
#include <memory> struct container { int type; std::shared_ptr<void> payload; container(int t, const void *p) : type(t), payload(p) { } }; int main() { homecoming 0; }
i'm trying create generic container using shared_ptr
type of void
. going switch on type , cast payload appropriate type.
i figured container ctn(1, new data());
think might have wrong well.
thanks.
you're trying initialise pointer void
pointer const void
, indeed illegal. "smartness" of pointer not matter, fail ordinary pointers well.
you either need alter type of payload
std::shared_ptr<const void>
, or (probably more want) alter type of p
void*
.
note, however, while technically solve immediate problem, can introduce more fundamental one. under design, payload
know nil actual type points, not phone call destructor of data
when lastly reference goes out. should rethink entire design utilize suitably typed pointers.
c++ struct shared-ptr
No comments:
Post a Comment