Math Help - C++, Return void?

1. C++, Return void?

My computing prof wrote this function in class, and I am so confused.

Code:
void *headptr()
{
}
What exactly is being returned here. Normally, head is of class type Node (one which we built), however I get errors when I try to assign a Node to it.

Like so
Code:
   Node *newnode = Object.*headptr();
Error: *headptr() cannot be uses as a member point ,since it is of type 'void*'
Any help would be appreciated

2. Originally Posted by Haven
My computing prof wrote this function in class, and I am so confused.

Code:
void *headptr()
{
}
What exactly is being returned here. Normally, head is of class type Node (one which we built), however I get errors when I try to assign a Node to it.

Like so
Code:
   Node *newnode = Object.*headptr();
Error: *headptr() cannot be uses as a member point ,since it is of type 'void*'
Any help would be appreciated
I don't know enough pointer syntax to be able to say what exactly was causing your compiler error, but I was able to find out that the function returns a void pointer; if you do an internet search for: void pointer, you will find relevant hits.

The main usefulness seems to be that void pointers can point to any data type and can be cast accordingly.

3. What is headptr? Just a regular function, or a member function (i.e. one defined inside a class)?

Note that in C++ there is no automatic conversion from a void * to any other pointer and vice versa, as it was true in C, so you must explicitly cast.

Also, "head" is unlikely to be of type Node, but rather Node *, since you can't cast a class to a pointer type.

And I'm not sure what you're trying to achieve with that assignment. If you want to allocate a new node (on the heap), use

Code:
Node *foo = new Node;
otherwise, if you've already got a node pointer and you want to assign to it the value of the head, use

Code:
Node *head = headptr();

4. Pointers to void are not used much in C++ since templates offer similar functionality.

5. You can not do this: