Obj-C++ Example
Obj-C++ Example
- Subject: Obj-C++ Example
- From: Stuart Bryson <email@hidden>
- Date: Fri, 9 Nov 2001 14:18:40 +1100
Hi All,
I know that Obj-C++ is not the desirable approach. However I wish to
develop an Altivec application and it seems that all the Altivec
examples are in C++. Also it seems that Templates would be highly useful
and they too are a C++ feature. So I plan to use Obj-C for the most part
of my program with a bit of C++ for the Altivec computations.
I have read the docs...
/Developer/Documentation/ReleaseNotes/Objective-C++.html
but even when I copy and paste their example into PB, it doesn't
compile. The same occurs when I try my own code. In the example (given
below), the error I keep getting is:
HelloWorld.mm:6: parse error before character 0312
Has anyone successfully got this to work. Is there a compiler flag that
I must set? My file name is .mm which as I understand is the Obj-C++
extension. Any help would be greatly appreciated.
Stuart
// HelloWorld.mm
#import <Cocoa/Cocoa.h>
class HelloWorld;
@interface PLog: NSObject {
HelloWorld *ptr;
}
- (void)sayHello;
- (void)sayHi: (HelloWorld *)p;
- (id)init;
- (void)dealloc;
@end
class HelloWorld {
id printLog;
public:
HelloWorld(bool b) { if(b) printLog = [[PLog alloc] init]; }
~HelloWorld() { [printLog release]; }
void sayHi() { printf(Hi); }
void sayHello() { [printLog sayHi: this]; }
};
@implementation PLog
- (void) sayHello { NSLog(@"Hello, World!"); }
- (void) sayHi: (HelloWorld *)p { p->sayHi(); }
- (id) init { [super init]; ptr = new HelloWorld(false); return self; }
- (void) dealloc { delete ptr; [super dealloc]; }
@end