a generic pointer to pointers (c++ issue)

Started by
6 comments, last by kalash 20 years, 4 months ago
Hi all, Can you exlain me how to assign pointers to generic pointers (void*) cast, and to generic pointer to pointers (void**) cast... i think i know... correction, i thought i knew Regards, kalash
Advertisement
You want to obtain a normal pointer from a void pointer?

int *Ptr = (int*) void_ptr;

You want the value of a void pointer?

int Value = *(int*) void_ptr;

You want to assign a normal pointer from a pointer pointer?

void *new_ptr = *void_ptr;

Not void?

int *new_ptr = (int*) *void_ptr;

Sorry if I misread the problem.

Jiia
Yup yup yup.... ahhh all those notations.. YOURE WORTH REAL MONEY, thanks so much for your help ))) I really needed that as i haven''t seen c++ for years and couldnt be bothered to go read the books again.

btw sorry if my english is not good...
Err... C++... generic programming... void*? No, no, no; templates.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
YOURE WORTH REAL MONEY

LOL! I like that, good compliment.

And it was no problem.

Jiia
if your going to cast pointers to void.. you should use C++ casting

void* pvoid = reinterpret_cast<void*>(pint);
void** ppvoid = reinterpret_cast<void**>(ppint);

(void*) is old c-style casting
quote:Original post by Anonymous Poster
if your going to cast pointers to void.. you should use C++ casting

void* pvoid = reinterpret_cast<void*>(pint);
void** ppvoid = reinterpret_cast<void**>(ppint);

(void*) is old c-style casting



When dealing with void pointers, its a good idea to explicitly cast.
And the rockets' red glare, the bombs bursting in air,gave proof through the fight that our flag was still there.Oh say, does that star-spangled banner yet waveover the land of the free and the home of the brave?
quote:Original post by PlayGGY
quote:Original post by Anonymous Poster
if your going to cast pointers to void.. you should use C++ casting

void* pvoid = reinterpret_cast&lt;void*&gt;(pint);
void** ppvoid = reinterpret_cast&lt;void**&gt;(ppint);

(void*) is old c-style casting



When dealing with void pointers, its a good idea to explicitly cast.

That is explicit casting, C++ style.

This topic is closed to new replies.

Advertisement