8
我想在我的ViewController中調用C++類。所以我創建這樣一個類: Hello.h「接收器類型,例如消息是一個前向聲明」在xcode 4.6
#import <Foundation/Foundation.h>
@interface Hello : NSObject{
class NewHello{
private:int greeting_text;
public:
NewHello(){
greeting_text=5;
}
void say_hello(){
printf("Greeting_Text = %d",greeting_text);
}
};
NewHello *hello;
}
-(void)sayHellooooo;
@end
Hello.mm
#import "Hello.h"
@implementation Hello
-(void)sayHellooooo{
hello = new NewHello();
hello->say_hello();
}
@end
ViewController.h
#import <UIKit/UIKit.h>
//#include "Hello.h"
@class Hello;
@interface ViewController : UIViewController{
}
@end
ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"dddddddd");
Hello *aa = [[Hello alloc]init];
[aa sayHellooooo];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
它在p中工作正常roject:http://files.cnblogs.com/cpcpc/Objective-C%E8%B0%83%E7%94%A8C.rar
但是,當我將代碼複製到我的項目,它顯示「接收器類型的實例消息是前向聲明」錯誤。
如果我更改「@class Hello」到#import「Hello.h」,在「NewHello類」中出現「Unkwon類型類,是否指Class」錯誤。
我使用xcode 4.6.任何人都可以幫助我嗎?謝謝!
它的工作原理!非常感謝您! – Willen
感謝它幫助了很多:) –