C++. Error: void is not a pointer-to-object type
You are dereferencing the void *
before casting it to a concrete type. You need to do it the other way around:
arguments vars = *(arguments *) (args);
This order is important, because the compiler doesn't know how to apply *
to args
(which is a void *
and can't be dereferenced). Your (arguments *)
tells it what to do, but it's too late, because the dereference has already occurred.
In C++, I'm getting a message error: 'void*' is not a pointer-to-object type
As the compiler message says, void*
is not a pointer to object type. What this means is that you cannot do anything with void*
, besides explicitly converting it back to another pointer type. A void*
represents an address, but it doesn’t specify the type of things it points to, and at a consequence you cannot operate on it.
error: ‘void*’ is not a pointer-to-object type what is the right solution?
You can't pass the array as void* because the element size is not known in this case and thus you're not able to access your elements. You have to change the signature of the partition function as following:
int partition(Point* arr, int start, int end, bool(*cmp_f)(Point*, Point*),
void(*swap_f)(Point*, Point*));
If partition() must support multiple types use templates as suggested in the comments:
template<typename T> int partition(T* arr, int start, int end, bool(*cmp_f)(T*, T*),
void(*swap_f)(T*, T*));
template<typename T> void quick_sort(T* pts, int start, int end, bool(*cmp_f)(T*, T*),
void(*swap_f)(T*, T*));
C++, “error: 'void*' is not a pointer-to-object type”
You are converting an integer value to pointer. Maybe you wanted to do this:
*((uint8_t *) values[0]) = (*((uint8_t *) values[0])+x);
*((uint16_t *) values[2]) = (*((uint16_t *) values[2])+x);
also see these questions: this question and this question
Error: ‘void*’ is not a pointer-to-object type
The problematic line is:
void* person_vp = (*loadPerson)();
You're dereferencing a void*
. You need this:
void* person_vp = (*reinterpret_cast<void* (*)()>(loadPerson))();
EDIT:
For better readability, the cast can be split like this:
typedef void* VoidFunc();
VoidFunc* loadPerson_func = reinterpret_cast<VoidFunc*>(loadPerson);
void* person_vp = (*loadPerson_func)();
Error: Why 'void*' is not a pointer-to-object type even though the pointer is set to an object?
The compiler has no clue what m_union
might actually be pointing at. You declared it as a void *
so the compiler believes you, it has no choice. And that's all it knows, so m_union->a
has to be flagged as an error, because ->a
has no meaning to the compiler here.
To put it another way, RTTI aside, pointers don't 'know' what they're pointing at. The compiler only knows how the pointer was declared.
I don't know what else to say, it's really that simple. I don't like having to say this, but looking at the code as a whole, it looks like a complete mess. Who wrote it?
[Edit] And what Jeffrey said will indeed fix it, but that's not what you asked.
Why do I get this error? void* is not a pointer to object type.
You are declaring a local variable void *stackAddr
, which shadows the global stackAddr
array.
Moreover, it is not an array, and applying the []
subscript operator attempts to offset and dereference a void
pointer, hence the compile error.
Dereferencing and pointer-arithmetic on void pointers is not permitted by the standard since sizeof(void)
is undefined.
error: 'void*' is not a pointer-to-object type
data
is of type void*
, so data->emp
would be of type void
, which you can't really have, much less assign to.
Related Topics
Store Results of Std::Stack .Pop() Method into a Variable
Quadruple Precision in C++ (Gcc)
Extract C++ Template Parameters
Is Constexpr a "Hint" (Like Inline) or "A Binding Request" to the Compiler
How to Store Variant Data in C++
Does Gdi+ Have Standard Image Encoder Clsids
In Which Versions of the C++ Standard Does "(I+=10)+=10" Have Undefined Behaviour
Does Calling a Destructor Explicitly Destroy an Object Completely
Get Key Press in Windows Console
Cmake Link Library Target Link Error
Fast Multiplication/Division by 2 for Floats and Doubles (C/C++)
Are Data Members Allocated in the Same Memory Space as Their Objects in C++