user2492388
user2492388

Reputation: 181

C++ - Invalid Conversion from 'void*' to 'uint8_t**'

I have a beginner question and I don't found any right way. In the header I had:

    static uint8_t **data = NULL;

and in my function then I want to:

    data = av_mallocz (sizeof (uint8_t*) *planes);

But here comes the error:

A Invalid Conversion from 'void*' to 'uint8_t**'

The av_mallocz function come from ffmpeg: return av_mallocz (nmemb *size);

Anyone an idea?

Upvotes: 0

Views: 4543

Answers (1)

RichardPlunkett
RichardPlunkett

Reputation: 2988

Try this:

data = (uint8_t**)av_mallocz (sizeof (uint8_t*) *planes);

Remember, the sizeof (uint8_t*) doesnt tell your code what type the data is going to be, it just helps calculate for the malloc how much space it needs. The malloc return generic space, which is why is uses void*. You still need to cast that void* to the type you want. Oh, and since this is C++, you might want to consider a static_cast<uint8_t**>(...), just to be nicer.

Upvotes: 4

Related Questions