Cannot convert 'const void *' to 'const char *' in C++

B

bg_ie

Hi,

I am using a API I downloaded from the internet programmed in C. I need
the function below which works with this api in my c++ file -

void StoreNoteCallback(void *context, int arglen, const void *args,
OSCTimeTag when,
NetworkReturnAddressPtr returnAddr)
{
const char *typeArgs = (const char *)args;
const float *floatArgs = &typeArgs[OSCPaddedStrlen(args)];
}

The problem is that the gives me the errors -

Cannot convert 'const void *' to 'const char *' in function
StoreNoteCallback
Type mismatch in parameter 's' (wanted 'const char *', got 'const void
*') in function StoreNoteCallback
Cannot convert 'const char *' to 'const float *' in function
StoreNoteCallbac

The above works in a c program. What's the problem and how do I fix it?

Thanks,

Barry.
 
V

Victor Bazarov

I am using a API I downloaded from the internet programmed in C. I
need the function below which works with this api in my c++ file -

void StoreNoteCallback(void *context, int arglen, const void *args,
OSCTimeTag when,
NetworkReturnAddressPtr returnAddr)
{
const char *typeArgs = (const char *)args;
const float *floatArgs = &typeArgs[OSCPaddedStrlen(args)];
}

The problem is that the gives me the errors -

Cannot convert 'const void *' to 'const char *' in function
StoreNoteCallback
Type mismatch in parameter 's' (wanted 'const char *', got 'const void
*') in function StoreNoteCallback

Which one is 's'? And you should be able to use 'static_cast' to fix
that...
Cannot convert 'const char *' to 'const float *' in function
StoreNoteCallbac

That can be remedied with 'reinterpret_cast'.
The above works in a c program. What's the problem and how do I fix
it?

Use 'reinterpret_cast':

const float *floatArgs = reinterpret_cast<const float*>(&type...

V
 
H

Heinz Ozwirk

Hi,

I am using a API I downloaded from the internet programmed in C. I need
the function below which works with this api in my c++ file -

void StoreNoteCallback(void *context, int arglen, const void *args,
OSCTimeTag when,
NetworkReturnAddressPtr returnAddr)
{
const char *typeArgs = (const char *)args;
const float *floatArgs = &typeArgs[OSCPaddedStrlen(args)];
}

The problem is that the gives me the errors -

Cannot convert 'const void *' to 'const char *' in function
StoreNoteCallback
Type mismatch in parameter 's' (wanted 'const char *', got 'const void
*') in function StoreNoteCallback
Cannot convert 'const char *' to 'const float *' in function
StoreNoteCallbac

What's the signature of OSCPaddedStrlen? Does it expect a const char* or a
const void*. Perhaps you should pass typeArgs to it instead of args.

Heinz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top