Initialize structure with shared_ptr <void>

I constantly encounter an error that makes sense no matching constructor for initialization of 'std::shared_ptr<void>', but I don’t know where to start.

Here is what I work for.

#include <memory>                                                                                                                                                             

struct Container {                                                             
  int type;                                                                    
  std::shared_ptr<void> payload;                                               

  Container(int t, const void *p) : type(t), payload(p) { }                    
};                                                                             

int main() {                                                                   
  return 0;                                                                    
}

I am trying to create a generic container using shared_ptrwith a type void. I was going to make a type switch, and then just pass the payload to the appropriate type.

I decided that I could just do something like Container ctn(1, new Data());that, but I think I might have it wrong too.

Thank.

+4
source share
3 answers

void const void, . "" , .

payload std::shared_ptr<const void>, (, , ) p void*.


, , , , . payload , , Data, . , , .

+2

: Boost.Any, , , , .

, void shared_ptr, void . shared_ptr , deleter . :

struct Container {
    int type;
    std::shared_ptr<void> payload;
    template<typename T>
      Container(int t, T* p) : type(t), payload(p) { }
};

, , , , .

+2

shared_ptr<T>

, , , , ( java-).

void*

+1

All Articles