Question

I am trying to cast auto_ptr to void pointer in the following manner:

void *AM::This2Ctx(std::auto_ptr<AMContext> data)
{
 return reinterpret_cast<void *>(data);
}

but i keep getting a compilation error:

error: invalid cast from type std::auto_ptr<AMContext> to type void*

how can this casting be done correctly? and how can it be used in the opposite way?

Was it helpful?

Solution

Use .get() to access the pointer held by auto-ptr :

reinterpret_cast<void *>(data.get());
                             ~~~~~~

In addition, auto_ptr is deprecated, use unique_ptr instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top