繁体   English   中英

C ++和Objective-c

[英]C++ and Objective-c

我构建了一个静态库,并将.h文件添加到我的项目中,

.h文件的所有类中,如下所示:

class StartOp
{
    static void openFiles(WavInFile **inFile, WavOutFile **outFile, const RunParameters *params);
    static void setup(SoundTouch *pSoundTouch, const WavInFile *inFile, const RunParameters *params);
    static void process(SoundTouch *pSoundTouch, WavInFile *inFile, WavOutFile *outFile);
    static void detectBPM(WavInFile *inFile, RunParameters *params);
    int start(const int nParams, const char * const paramStr[]);
};

我收到了这个错误:

StartOp.h:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'StartOp'

**编辑* *

我通过将文件ex更改为mm来解决此问题。 现在我想使用这段代码,我想从这个类调用,这段代码是一个c ++类,我想从Objective-c类中调用它:

#ifndef _STARTOP_H_
#define _STARTOP_H_

namespace soundtouch
{

    class StartOp
    {
        static void openFiles(WavInFile **inFile, WavOutFile **outFile, const RunParameters *params);
        static void setup(SoundTouch *pSoundTouch, const WavInFile *inFile, const RunParameters *params);
        static void process(SoundTouch *pSoundTouch, WavInFile *inFile, WavOutFile *outFile);
        static void detectBPM(WavInFile *inFile, RunParameters *params);
        static int start(const int nParams, const char * const paramStr[]);
    };
}



#endif

static int start(const int nParams, const char * const paramStr[]);

来自我的Objective-c iphone应用程序的方法。

您发布的代码不是C; 它更像是C ++。

现在,Objective-C和C ++可以互操作,但是你需要在Objective-C端使用.mm扩展。

所以,如果你要导入.h. 将文件放入.m文件中,显然会出现错误,因为编译器不期望class定义(C ++)。 如果你将.h文件导入.mm文件,你有可能它会工作(如果其余的都是正确的,我的意思是)。

如果您需要更多帮助,请提供更多代码,以便我们更好地了解您的工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM