If I have a void pointer that needs to point to a struct. I'm not sure how to access the struct through the pointer. Can I even do that? If so, how?

#include <iostream>

struct test
{
	int var1;
	int var2;
};

int main()
{
	void *pPointer;
	pPointer = new test;

	pPointer->var1 = 0;

	std::cout << pPointer->var1;
	return 0;
}

Changing it from void is not an option.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.