我剛開始接觸的Objective-C,但已經做了一堆C++應對其糾纏着我,因爲我一直在搞亂了我的Objective-C的語法警告:cWorld「可能不會‘+頁頭’
。我得到一個崩潰創建我的第一個Objective-C的對象。我認爲這可能與在頁頭功能此警告。
cWorld may not respond to '+alloc'
我見過很多修正爲「-alloc」,但沒有爲+ alloc。任何人有任何想法可能導致它?
崩潰是在ASM代碼,我沒有得到太多信息。該警告是下面看到worldContext.mm行... // *警告IS HERE
這是一個worldContext.mm段與所有world.mm的+ world.h
worldContext .mm
#import "worldContext.h"
#import "scenemanager.h"
#import "matrix4.h"
#import "world.h"
@implementation cWorldContext
- (void)Initialize {
mSceneManager = new cSceneManager();
mWorldObj =[[cWorld alloc] init]; //***** WARNING IS HERE
[mWorldObj Initialize: mSceneManager];
}
World.h
#ifndef __WORLD
#define __WORLD
class cModelBase;
class cSceneManager;
@interface cWorld {
cSceneManager* mSceneManager;
cModelBase* mWorldModel;
}
- (void)Initialize: (cSceneManager*) sceneManager;
- (void)Update;
- (void)Shutdown;
@end
#endif
World.mm
#import "world.h"
@implementation cWorld
- (void)Initialize: (cSceneManager*) sceneManager {
mSceneManager = sceneManager;
}
- (void)Shutdown {
}
- (void)Update {
}
@end
兩點意見:1),除非你在同一文件中混合目的的C和C++你並不需要一個.mm文件 - 一個.m文件會2)您可能會發現谷歌的Obj-C風格指南很有用:http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml – mharper 2011-03-29 23:25:51
@mharper給出了他如何在「mSceneManager」中創建「mSceneManager」 WorldContext.mm「,它會出現他使用Objective-C++。同意款式雖然:) – 2011-03-29 23:31:18