Question: I have an assignment where I have to use a linked list of node with void\* as the data. I would be filling the nodes with an object. I want to know some way of accessing the members of the object after it is in the linked list, other than casting it to the class. Is it possible? Also, here's a chunk of my code just in case it helps clarify my question.

```
struct Node
{
    void* data_;
    Node* next_;

    Node()
    {
        data_ = 0;
        next_ = 0;
    }
};

class Star
{
private:
    char name_[ENTRY_SZ];
    long temperature_;
    double luminosity_;
    double mass_;
    double radius_;

public:
    static char filePath_[ENTRY_SZ];

    Star(char* name);
    void SetTemperature(char* temp);
    void SetLuminosity(char* lum);
    void SetMass(char* mass);
    void SetRadius(char* rad);
    void PrintToConsole();
    void AppendToFile();
};

```

I want to be able to call the PrintToConsole function after it is in a void\*.

Answer: 
You cannot work with the pointee of a `void*` without first casting it first. If it points at a `Star`, for example, you could do something like this:

```
static_cast<Star*>(data_)->PrintToConsole(); // Haha, Star star!

```

That said, in C++, it's pretty unusual to store things like this. You're much better off using a template class so that you get back the type information you need.
You should cast it to the class. But if you really don't want to, you can use the [offsetof](http://en.cppreference.com/w/cpp/types/offsetof) macro:

> 
> The macro offsetof expands to a constant of type std::size\_t, the
>  value of which is the offset, in bytes, from the beginning of an
>  object of specified type to its specified member, including padding if
>  any.
>  If type is not a standard layout type, the behavior is undefined.
>  If member is a static member or a member function, the behavior is
>  undefined.
> 
> 
> 

But you should just cast it to the class.

EDIT: Ah, I see you want to access a method of the class. That's not possible. You should cast it to the class.