title: Objective-C++ / Cocoa attempt to create a window with button, not working?
body: <p>I'm supposed to create a c++ class with c++ methods, that are made of objective-c and use cocoa, but now I've ran into a problem, and simply can't figure it out, cause I'm pretty new at objective-c. Also the point is that I should be able to create windows and buttons from c++. So when ever I build and run this program, it starts up but then instantly turns into a "not responding" state. Anyways, here's what I got:</p>
  
  <p>Window.h</p>
  
  <pre><code>#ifndef WINDOW_H
  #define WINDOW_H
  
  class Window {
      public:
          Window();
          void createButton();
  };
  
  #endif
  </code></pre>
  
  <p>Window.mm</p>
  
  <pre><code>#include "Window.h"
  #include "Button.h"
  
  Window::Window(){
      NSWindow *window = [[NSWindow alloc]
          initWithContentRect: NSMakeRect(100, 100, 200, 200)
          styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask
          backing: NSBackingStoreBuffered
          defer: NO];
      [window setTitle: @"Test window"];
  }
  
  void Window::createButton(){
      Button *button;
      [[this contentView] addSubView: button];
  // word this gives warning: no '-addSubView:' method found
  // this is probably causing the problem I have
      }
  </code></pre>
  
  <p>Button.h</p>
  
  <pre><code>class Button{
      Button();
  };
  // There will be more methods here eventually
  </code></pre>
  
  <p>Button.mm</p>
  
  <pre><code>#include "Button.h"
  Button::Button(){
      NSButton *button = [[NSButton alloc]
          initWithFrame: NSMakeRect(14, 100, 120, 40)];
      [button setTitle: @"Hello world"];
      [button setAction: @selector(invisible)];
      [button setBezelStyle: NSRoundedBezelStyle];
      [button setButtonType: NSMomentaryLightButton];
      [button setBezelStyle: NSTexturedSquareBezelStyle];
  }
  </code></pre>
  
  <p>Main.cpp</p>
  
  <pre><code>#include "Window.h"
  #include "Button.h"
  
  int main(int argc, char *argv[]){
      Window x;
      x.createButton();
  }
  </code></pre>
  
  <p>So, does anyone have any idea why ain't it working, like I mentioned, I'm pretty new at Cocoa and Objective-C, still learning :P
  And yeah, I've tried to fix it.</p>