Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AppDelegate.h/cpp - Generated by Cocoa app wizard
- //
- // AppDelegate.h
- // helper
- //
- // Created by Hariharan Mahadevan on 2019/9/25.
- // Copyright © 2019 smallpearl. All rights reserved.
- //
- // Important:
- // By default XCode wizard generates AppDelegate.h as 'Objective-C Header'.
- // This has to be changed to 'Objective-C++ Header' in the File Inspector.
- #include <string>
- #include <memory>
- #import <Cocoa/Cocoa.h>
- // A dummy C++ objects to illustrate their creation/destruction from
- // Objective-C code.
- struct DummyObject {
- char buf[1000];
- };
- struct HelperApp {
- std::string _name; // should also involve memory alloc/dealloc
- // Use unique_ptr to test memory alloc/dealloc
- std::unique_ptr<DummyObject> _dummy;
- HelperApp();
- virtual ~HelperApp();
- };
- @interface AppDelegate : NSObject <NSApplicationDelegate>
- {
- HelperApp* _helperApp;
- }
- @end
- // AppDelegate.cpp
- //
- // AppDelegate.cpp
- // helper
- //
- // Created by Hariharan Mahadevan on 2019/9/25.
- // Copyright © 2019 smallpearl. All rights reserved.
- //
- // Important:
- // By default XCode wizard generates AppDelegate.m. This file has to be renamed to
- // AppDelegate.cpp and the file type has to be changed from 'Objective-C Source'
- // to 'Objective-C++ Source' in the File Inspector.
- #import "AppDelegate.h"
- HelperApp::HelperApp()
- : _name("HelperApp"), _dummy(new DummyObject)
- {
- NSLog(@"Helper::Helper");
- }
- HelperApp::~HelperApp()
- {
- NSLog(@"Helper::~Helper");
- }
- @interface AppDelegate ()
- @property (weak) IBOutlet NSWindow *window;
- @end
- @implementation AppDelegate
- - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
- // Insert code here to initialize your application
- _helperApp = new HelperApp();
- }
- - (void)applicationWillTerminate:(NSNotification *)aNotification {
- // Insert code here to tear down your application
- delete _helperApp;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement