title: C++ How does a relation of pointers and class members work?
body: <p>in the example below I've made a very simple class and there are a couple of things which I don't understand.</p>
  
  <pre><code>class Keylogger {
  public:
      void Hook();
      void Unhook();
  
  private:
      HHOOK hHook;
      LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
  };
  
  void Keylogger::Hook() {
  
      HINSTANCE hInstance = GetModuleHandle(NULL);
  
      hHook = SetWindowsHookEx(WH_KEYBOARD_LL, this-&gt;LowLevelKeyboardProc, hInstance, 0);
  }
  
  void Keylogger::Unhook() {
      UnhookWindowsHookEx(hHook);
  }
  </code></pre>
  
  <p>If I understand correctly, all members of a class are local (in stack) when the class object is defined and destroyed once operations ends. (function exits).</p>
  
  <p>In the example above, I'm trying to assign HHOOK to a private member hHook, thus receiving an error: <strong>"non-standard syntax; use '&amp;' to create a pointer to member"</strong></p>
  
  <p>Why can't a variable just be assigned that way and what does the error exactly mean? </p>
  
  <p>In which case should pointers be created to members and how exactly should those be used with <strong>this-></strong>? Thanks!</p>