5

ok I have a variable

void * vp

passed through a function proccessData (void * vp)

I have a function that accept the following as a parameter

findIDType(const char* const pointer) and wanted to pass the pv as findIDType(pv)

compiled with GNU 2.95.3

cannot use any other compiler btw.

the issue is that the compiler doesnt give me why it is not acceptable, it just print out a message cannot without any useful description.

how to cast that? from void* to const char* const

I have tried (char*)pv, (const char*)pv and (const char* const)pv without any luck

aah134
  • 860
  • 12
  • 25

1 Answers1

3

You have to use reinterpret_cast, and cast to the complete type you would like to pass, this should work:

const char* const ptrTpPass = reinterpret_cast<const char* const>(vp);

But as mentioned in the comments, static_cast would work too and is actually preferable:

const char* const ptrTpPass = static_cast<const char* const>(vp);
tambre
  • 4,625
  • 4
  • 42
  • 55
Ilya Kobelevskiy
  • 5,245
  • 4
  • 24
  • 41
  • 2
    Prefer `static_cast` when casting some pointer from `void*`. In fact, `reinterpret_cast` is probably not allowed for `void*` in his old compiler. [See this for more info](http://stackoverflow.com/questions/310451/should-i-use-static-cast-or-reinterpret-cast-when-casting-a-void-to-whatever). Also using `static_cast` with the example works fine on my compiler (GCC4.8.1). – Felix Glas Oct 25 '13 at 14:38
  • I am recompiling and testing both – aah134 Oct 25 '13 at 14:54