【发布时间】:2015-02-12 06:34:27
【问题描述】:
我需要在目标 c 中为 C++ 类编写一个包装类。
我参考了以下Can't find standard C++ includes when using C++ class in Cocoa project 并且能够摆脱词法或预处理器问题:'vector' file not found 问题。
但是,我不明白将接受多个参数的 C++ 方法转换为目标 c 方法。
有人可以帮我这样做吗?我想做的是为这个http://breakfastquay.com/rubberband/code-doc/classRubberBand_1_1RubberBandStretcher.html#a0af91755d71eecfce5781f2cd759db85写一个包装类
我已经尝试过这样做,以下是我坚持的方法......
// Wrapper.h
#import <Foundation/Foundation.h>
@interface Wrapper : NSObject {
void *myRubberBandStretcher;
}
#pragma mark - Member Functions
-(void)process:(const float)input samples:(size_t)samples final:(bool)final;
@end
/////////////////////////////////////// ////////////////////////////////////p>
//Wrapper.mm
#import "Wrapper.h"
#import "RubberBandStretcher.h"
@implementation Wrapper
-(id)init {
self = [super init];
if (self) {
myRubberBandStretcher = new RubberBand::RubberBandStretcher::RubberBandStretcher(44100, 2, 0, 1.0, 1.0);
}
return self;
}
-(void)process:(const float)input samples:(size_t)samples final:(bool)final {
static_cast<RubberBand::RubberBandStretcher *>(myRubberBandStretcher)->process(<#const float *const *input#>, <#size_t samples#>, <#bool final#>)
}
【问题讨论】:
-
我猜你不需要在 Objective-C 中为 C++ 创建特殊的包装类。只需将实现文件扩展名从 .m 更改为 .mm,您的 C++ 代码就会开始编译和运行。
-
我已经为橡皮筋库创建了静态库,并且只得到了 RubberBandStretcher.h 文件。头文件是用 C++ 编写的。当我导入头文件并转到头文件并给我“词法或预处理器问题:'向量'文件未找到问题”错误。我已经摆脱了stackoverflow.com/questions/6083764/… 之后的错误所以我想我需要写一个包装器
-
您可以将文件扩展名更改为 .mm 以使用 c++ 语法,对吗?那么就不需要对包装器进行修正了。
-
@Arjuna 正如我上面所说的,我只有头文件和静态库。头文件扩展名为 .h。没有 .m 文件我正在为它编写包装类并且有 .h 和 .mm 文件。我在上面的问题中包含了 .h 文件和 .mm 文件,但对如何转换 breakfastquay.com/rubberband/code-doc/… 文件中可用的 c++ 方法感到困惑
-
@Arjuna 我试图转换为目标 c 的方法就是这种方法; void RubberBand::RubberBandStretcher::process ( const float *const * input, size_t samples, bool final ) 我不知道如何将其转换为目标 c,因为它要求该方法的几个参数。如果您需要查看完整代码,我可以为您上传项目。谢谢
标签: ios objective-c objective-c++ rubber-band