2011-03-29 53 views
0

我刚开始接触的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 
+0

两点意见:1),除非你在同一文件中混合目的的C和C++你并不需要一个.mm文件 - 一个.m文件会2)您可能会发现谷歌的Obj-C风格指南很有用:http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml – mharper 2011-03-29 23:25:51

+0

@mharper给出了他如何在“mSceneManager”中创建“mSceneManager” WorldContext.mm“,它会出现他使用Objective-C++。同意款式虽然:) – 2011-03-29 23:31:18

回答

8
@interface cWorld { 

应该

@interface cWorld : NSObject { 
+0

+1。如果你想从你的类中调用NSObject方法,你需要从'NSObject'继承。 – 2011-03-29 23:10:08

+1

你也想要命名你的类'CWorld',而不是'cWorld';类以大写字母开头(小写方法)。 – bbum 2011-03-30 03:55:36

相关问题