gpt4 book ai didi

c++ - 没有用于初始化的匹配构造函数 - C++ 和 Objective C

转载 作者:行者123 更新时间:2023-11-28 00:03:09 25 4
gpt4 key购买 nike

我正在尝试以这种方式将自定义 C++ 类集成到 Objective C 类中:

C++ 类头

class Analyzer
{

public:

Analyzer(std::string const& face_cascade_url, std::string const& eyes_cascade_url, std::string const& nose_cascade_url );

};

Objective-C header :

@interface cvVideoWrapper : UIViewController <CvVideoCameraDelegate>

@property Analyzer analyzer;

@end

Objective-C 实现:

@implementation cvVideoWrapper


-(void) get_ready {

NSString* face_filename = [[NSBundle mainBundle]
pathForResource:@"haarcascade_frontalface_alt2"
ofType:@"xml"];
NSString* eyes_filename = [[NSBundle mainBundle]
pathForResource:@"haarcascade_eye_tree_eyeglasses"
ofType:@"xml"];
NSString* nose_filename = [[NSBundle mainBundle]
pathForResource:@"haarcascade_mcs_nose"
ofType:@"xml"];

self.analyzer = Analyzer([face_filename UTF8String], [eyes_filename UTF8String], [nose_filename UTF8String]);
}

@end

我在 Objective C 实现中遇到了这个错误:

No matching constructor for initialization of 'Analyzer'

我该如何解决这个问题?

最佳答案

我建议在这里使用前向声明来清理您的 header 。并使用指针而不是实例。

Objective-C header :

class Analyzer;

@interface cvVideoWrapper : UIViewController <CvVideoCameraDelegate>

@property Analyzer* analyzer;
// ^^ it is a pointer now

@end

然后在 Objective C 实现中:

@implementation cvVideoWrapper

-(void) get_ready {

NSString* face_filename = [[NSBundle mainBundle]
pathForResource:@"haarcascade_frontalface_alt2"
ofType:@"xml"];
NSString* eyes_filename = [[NSBundle mainBundle]
pathForResource:@"haarcascade_eye_tree_eyeglasses"
ofType:@"xml"];
NSString* nose_filename = [[NSBundle mainBundle]
pathForResource:@"haarcascade_mcs_nose"
ofType:@"xml"];

// Create object here with new:
self.analyzer = new Analyzer([face_filename UTF8String], [eyes_filename UTF8String], [nose_filename UTF8String]);
}

// Don't forget to cleanup when you're done:
- (void)dealloc
{
delete self.analyzer;
[super dealloc];
}

@end

关于c++ - 没有用于初始化的匹配构造函数 - C++ 和 Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37423582/

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