"Attempting to use the forward class 'Game' as superclass of 'MathGame'" in Cocos2d
You simply have an import cycle:
Game
importsSplashScreenLayer
SplashScreenLayer
importsMathGame
MathGame
importsGame
Your solution:
Leave the import
inside the MathGame
, and change the other imports to @class.
To sum it up:
// Game.h#import "cocos2d.h"#import <GameKit/GameKit.h>@class SplashScreenLayer;@interface Game : CCLayer // A bunch of stuff@endThe new game type:// MathGame.h#import "Game.h"@interface MathGame : Game@endAnd the main menu that includes both:// SplashScreen.h#import "cocos2d.h"#import "HowToPlayLayer.h"#import "AboutLayer.h"@class Game;@class MathGame;@interface SplashScreenLayer : CCLayer // A bunch of stuff@end
With your question answered above, let me explain a few things I already know from reading about forward declerations and import cycles:
First, go read about them! They are a very important part of Objective-C, and you don't want to miss it!
Secondly, use @class whenever you need that class for private variables or method parameters. Use imports for inheritance and strong properties.
Thirdly, don't forget to #import
your forwarded classes in the implementation file!
In my case,I user the xx class and use the @class but not #import the .h file.and the compile complain..