473,714 Members | 2,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 StoreNoteCallba ck(void *context, int arglen, const void *args,
OSCTimeTag when,
NetworkReturnAd dressPtr 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
StoreNoteCallba ck
Type mismatch in parameter 's' (wanted 'const char *', got 'const void
*') in function StoreNoteCallba ck
Cannot convert 'const char *' to 'const float *' in function
StoreNoteCallba c

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

Thanks,

Barry.

Aug 17 '06 #1
3 13941
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 StoreNoteCallba ck(void *context, int arglen, const void *args,
OSCTimeTag when,
NetworkReturnAd dressPtr 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
StoreNoteCallba ck
Type mismatch in parameter 's' (wanted 'const char *', got 'const void
*') in function StoreNoteCallba ck
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
StoreNoteCallba c
That can be remedied with 'reinterpret_ca st'.
>
The above works in a c program. What's the problem and how do I fix
it?
Use 'reinterpret_ca st':

const float *floatArgs = reinterpret_cas t<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.co mschrieb im Newsbeitrag
news:11******** **************@ b28g2000cwb.goo glegroups.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 StoreNoteCallba ck(void *context, int arglen, const void *args,
OSCTimeTag when,
NetworkReturnAd dressPtr 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
StoreNoteCallba ck
Type mismatch in parameter 's' (wanted 'const char *', got 'const void
*') in function StoreNoteCallba ck
Cannot convert 'const char *' to 'const float *' in function
StoreNoteCallba c
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<cha r*>(pv);

--

Frederick Gotham
Aug 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
22048
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate example). int foo(const char* argv) { return 0; } int main(int argc, char* argv) {
6
16050
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void PushUnique(int); for(y = 0; y < 9; y++)
1
2883
by: Steven Woody | last post by:
somewhere in my code, char* rtnStrs = { "ok", "error", NULL }; foo( rtnStrs ); here, foo was decleared as 'void foo( const char * rtnStrs ). but the gcc compiler will report ' can not convert from char ** to const char ** '. i usually know that one can not convert a const to a non-const, but why here i can not convert a non-const to const ?
65
21441
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. #include <string.h> #include <stdio.h> /* Convert an ipv4 address to long integer */ /* "192.168.1.1" --> 3232235777 */ unsigned long iptol(char *ip){
18
20566
by: ReaperUnreal | last post by:
I've got a strange problem here. I need to take a value that I have written down on a sticky-note here, and find what's at that address in current memory. I've tried the following: void *value = 0x00323c68; but I get a typecasting error. If I do the following: void *value = static_cast<void *>(0x00323c68);
10
26621
by: sposes | last post by:
Im very much a newbie but perhaps somehone can help me. Ive been searching for a way to convert a std::string to a unsigned char* The situation is I have a function that wants a unsigned char* and I want to give it a std::string no matching function for call to `MD5::update(std::string&, size_t)' candidates are: void MD5::update(unsigned char*, unsigned int) void PrintMD5(string str){
1
10328
by: asenthil | last post by:
Hai this is senthil... I had tried to write a string which fetched from a database. into a file... when i tried to compile the solution the following error occurs like this error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char ' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2
9153
by: nassim.bouayad.agha | last post by:
Hello, here is a code snippet showning my problem : template<typename _K> class TClass1 { public: void Process(const _K& arg) const {
1
14970
codexparse
by: codexparse | last post by:
I am writing a browser program in C++ Builder 6 that loads a web page using the following code: void __fastcall TForm1::ToolButton1Click(TObject *Sender) { wchar_t buff; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, "http://www.thescripts.com", -1, buff, sizeof(buff)); CppWebBrowser1->Navigate(buff, 0, 0, 0, 0); } To include the address bar implementation, I need a temporary string derived from an edit box. This is...
0
8808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8712
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9316
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9077
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4727
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.