gpt4 book ai didi

ios - xcode 4.6 中的 "Receiver type for instance messages is a forward declaration"

转载 作者:技术小花猫 更新时间:2023-10-29 10:44:26 26 4
gpt4 key购买 nike

我想在我的 ViewController 中调用 C++ 类。所以我创建了一个这样的类:你好.h

#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

你好.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

在项目中运行良好:http://files.cnblogs.com/cpcpc/Objective-C%E8%B0%83%E7%94%A8C.rar

但是当我将代码复制到我的项目时,出现“Receiver type for instance messages is a forward declaration”错误。

如果我改变“@class Hello;” #import "Hello.h",在"class NewHello"中出现"Unkwon type class, did you mean Class"错误。

我使用的是 xcode 4.6。有人能帮帮我吗?谢谢!

最佳答案

问题是(如您所述)ViewController.m 的文件类型是 Obj-C 而 Hello.h 是 Obj-C++ 文件。解决方案是添加

#import "Hello.h" 

到您的 ViewController.m 文件并将 ViewController.m 的文件类型更改为 Obj-C++(从右侧面板)

关于ios - xcode 4.6 中的 "Receiver type for instance messages is a forward declaration",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15719681/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com