Illegal Implicit Conversion from 'void *'
One of the most common questions I see on the Palm OS forums goes something like this:
I am trying to solve this problem. I have looked at the Palm OS Reference book and trying to to why this problem is happening.
Error Getting:
Error : illegal implicit conversion from 'void *' to 'ListType *'
Training.cpp line 664 lst = FrmGetObjectPtr(frm, itemIndex);
This is a C++ error, not a Palm OS programming error. I've written a few questions and answers to help you understand this error.
Q. What is the return type of FrmGetObjectPtr?
A. void *
Q. What is the type of lst?
A. ListType *
Q. Does C++ let you implicitly convert from void * to other pointer types?
A. No; you must explicitly cast a void * to another pointer.
Q. How do you write this using C++ notation?
A. lst = static_cast<ListType *>(FrmGetObjectPtr(frm, itemIndex));
Q. How do you write this using C notation?
A. lst = (ListType *)FrmGetObjectPtr(frm, itemIndex);
Q. Why is C++ more strict than C?
A. Because the idea of types in C++ is a lot more powerful than C, since types are used to determine what functions are called when there is an overloaded function or method. If void pointers converted to other pointer types implicitly, it would be easy to get into an ambiguous situation.
Wizards and C++
Wizard-generated C++ programs in CodeWarrior for Palm OS V8 have a two special template functions defined in the program header. These are forms of GetObjectPtr that use a template argument to adapt their return values to the right pointer type. Check out the header file generated for your project to see their definitions.

Send feedback to combee@techwood.org
Copyright © 2004 Benjamin L. Combee
Palm OS is a registered trademark of PalmSource, Inc.
Metrowerks and CodeWarrior are registered trademarks of Metrowerks Inc.
The views expressed on this website/weblog are those of mine alone and do not necessarily reflect the views of PalmSource or Metrowerks.

qwertYAK / frobnovich
|