I have read through many of the previous posts on C4700, but I can't seem to find a solution to my problem.
I have a little script written to demonstrate struct pointers:
int * bar;
using namespace std;
foo * fooptr;
int * num;
*num = 25;
*fooptr->bar = *num;
cout << "now fooptr points to a foo struct whose bar points to: " << *fooptr->bar;
fooptr->bar = num;
cout <<"now fooptr's struct's bar shares memory address with num at " <<num;
Uninitialized variables are not initialized to random values, they are uninitialized. On a machine code level, they have whatever value was there when they were created. This may or may not be the address of an actual object. Either way, it is undefined behavior to try to access an uninitialized pointer value as if there is an object at that address.
So, your compiler is doing you a favor by issuing a warning (it is not required to do so), because your code has undefined behavior.
then is there an easy workaround for this problem?
Set your pointers to point to valid objects before dereferencing them. If you don't, then there are no promises about what behavior your program will have.