   Confusion with pointers...
  Having diagnosed that I actually don't really have a clue about how pointers really work, I decided to start playing around with them a bit more...As you might have guessed, I got stuck :SI'm trying to do the following. I have a class in which I have a MSG-struct declaration, and I want it to be a 'pointer' to the MSG struct that is used by windows to put messages in.Furthermore, I want to retrieve the members of the struct pointed to by the MSG pointer and put them in a 'local MSG-struct copy'...The class would look like this:// The class declaration, I only put in the relevant code...class SampleClass{    public:   SampleClass(){}   ~SampleClass(){}   void SetMsgPointer ( MSG * msgstruct );   void GetMsgInfo ( void ); /* Some other variables and functions...*/    private:   MSG * msg;   MSG localcopy;   /* Some other variables etc... */};// The SetMsgPointer functionvoid SampleClass::SetMsgPointer ( MSG * msgstruct ){    *msg = *msgstruct;}// The GetMsgInfo functionvoid SampleClass::GetMsgInfo ( void ){    localcopy.message = *msg.message;    localcopy.lParam = *msg.lParam;    localcopy.wParam = *msg.wParam;}An example of how it would be used can be found below, but the whole pointer stuff is incorrect because it keeps saying "left of '.message' must have class/struct/union type" which indicates ( in my eyes ) that 'msg' doesn't point to the actual MSG struct..  SampleClass sc;  sc.SetMsgPointer ( &msg )   // Reference to already declared MSG struct...  sc.GetMsgInfo ();How would I fix my pointers to make it work? Any advice would be dearly appreciated...   
  Without commenting on larger software design issues, here are a couple of things you might try:// The SetMsgPointer functionvoid SampleClass::SetMsgPointer ( MSG * msgstruct ){    //*msg = *msgstruct;    // It seems this should be...    msg = msgstruct;}// The GetMsgInfo functionvoid SampleClass::GetMsgInfo ( void ){    //localcopy.message = *msg.message;    //localcopy.lParam = *msg.lParam;    //localcopy.wParam = *msg.wParam;    // For this, try:    localcopy.message = (*msg).message;    localcopy.lParam = (*msg).lParam;    localcopy.wParam = (*msg).wParam;    // Or simply:    localcopy = *msg;    // If operator=() is suitably defined for the MSG class.};  void SampleClass::SetMsgPointer ( MSG * msgstruct ){    *msg = *msgstruct;}this copies the structure referenced by the pointer msgstruct into the structure referenced by pointer msg.because msg is not initialized, you get an exception on that point.to correct this you have following options (depending on what you actually want to do):1.   msg = msgstruct; // just store the pointer to the original structin this case localcopy ist useless.2.  localcpoy = *msgstruct;  // make a local copy  msg = &localcopy;   // and reference this copy;  Wow, thanks for the fast replies. I got it compiled without errors now, although I will have to study on the subject a bit more as it still looks too much like magic :P   ;const Msg sampleClass::GetMsgInfo (/*something*/){    ////};  There are 2 mistakes you've made:1)*msg = *msgstruct;That doesn't set the pointer msg, since you are dereferencing the pointers. It assigns the MSG structure that is referenced by "msg" to the MSG structure that is referenced by "msgstruct". Since you haven't allocated any memory for msg, the program will probably crash or you'll corrupt the heap. What you should do is:msg=msgstruct;Now msg and msgstruct point to the same MSG structure.2)localcopy.message = *msg.message;That tells the compiler to dereference "msg.message", not "msg". Even if "message" was a pointer(which it isn't), still msg.message does not exist, since msg is an MSG*, not an MSG. What you should do is:localcopy.message = (*msg).message;or better yet:localcopy.message = msg->message;However, all those are just syntactic knowledge. The whole example doesn't really do anything useful, so I don't know how much you'll really learn about pointers by using them in situations where they're not needed.-EDIT: Too late... [smile]   ;  Not too late mikeman ;)Your explanation was very clear and gave a useful insight into my mistakes.Also, the example doesn't look very useful because I ripped it from it's context. Basically I'm making a winsock wrapper as my first real project apart from some console and win32 stuff to learn C++ by constantly walking into problems :PAnyway, a user of the wrapper can set a flag like "SET_ASYNC" in the initialization function and then the wrapper takes care of intercepting winsock messages. Therefore I needed to have this pointer to the message struct or I wouldn't be able to intercept winsock messages.The copying to a local struct is also ripped from it's context as the local struct is not of type MSG, but a self-created SOCKETMSG struct with which I supply some easy functions to retrieve the network messages ;)   