Hi,

I have to pass a void pointer in a function and at the other end I have to read some values from this void pointer.
I planned of creating a class and setting up required variables into an object and then I set this

void* ptr = obj

when I read it on the other end I am getting the following error:

"error: 'void*' is not a pointer-to-object type"

some one please help!

Recommended Answers

All 4 Replies

You might to include just a bit more of the code...I have no idea what a obj is. Is it a variable, a reference to a variable, a pointer....

Your error. Did you try casting the void pointer to the appropriate type.

Constructor of my class

CookieData :: CookieData(int s1, int d1, int t1, char* ipfile1)
{
	s = s1;
	d = d1;
	t = t1;
	ipfile = ipfile1;
}

passing this class object

CookieData* cookiedata = new CookieData(s,d,t,ipfile);
	void cookie = &cookiedata;
	setfunction(cookie);   //function where I want these values, cookie has to be a void pointer by function declaration
CookieData* cookiedata = new CookieData(s,d,t,ipfile);
	void cookie = &cookiedata;
	setfunction(cookie);   //function where I want these values, cookie has to be a void pointer by function declaration

I'm pretty sure you want something like this:

CookieData* cookiedata = new CookieData(s,d,t,ipfile);
	void *cookie = cookiedata;
	setfunction(cookie);

yeah..I figured it.. basically I type casted the void pointer with a object type pointer and then I could use it as a object!

Thanks for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.