C++ and Objective-c
i built a static library,and add the .h
file to my project,
in all the class in the .h
files,something like this :
class StartOp
{
static void 开发者_如何学JAVAopenFiles(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[]);
};
i got this error:
StartOp.h:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'StartOp'
**EDIT**
i fix this problem by changing the file ex to mm. now i want to use this code and i want to call from this class ,this code is an c++ class that i want to call him from an objective-c class:
#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
to the
static int start(const int nParams, const char * const paramStr[]);
method from my objective-c iphone app.
The code you posted is not C; it is rather C++.
Now, Objective-C and C++ can interoperate, but you need to use .mm
extensions on the Objective-C side.
So if you are importing the .h.
file into a .m
file, you get obviously errors because the compiler is not expecting a class
definition (C++). If you import the .h
file into a .mm
file, you have some chance that it will work (if all the rest is correct, I mean).
If you need more help, please provide more code, so that we can understand better what you are doing.
精彩评论