468,484 Members | 2,064 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

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

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.

Aug 17 '06 #1
3 11738
bg***@yahoo.com wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 17 '06 #2
<bg***@yahoo.comschrieb im Newsbeitrag
news:11**********************@b28g2000cwb.googlegr oups.com...
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

Aug 17 '06 #3
Cannot convert 'const void *' to 'const char *'

void *pv = 0;

char *pc;

pc = static_cast<char*>(pv);

--

Frederick Gotham
Aug 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Brad Moore | last post: by
1 post views Thread by Steven Woody | last post: by
65 posts views Thread by kyle.tk | last post: by
18 posts views Thread by ReaperUnreal | last post: by
10 posts views Thread by sposes | last post: by
2 posts views Thread by nassim.bouayad.agha | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.