私はクロスプラットフォームのC++アプリに取り組んでいます。Macバージョンでは、obj-cで少しココアを使用する必要があります。そこで、OSXSpecificsというクラスを作成しました。このクラスには、アプリの他の部分と同様に、.mmファイル拡張子とc++ヘッダーがあります。
std::string OSXSpecifics::GetOSXFilePath(const char *name, const char *type) {
return [[[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String: name]
ofType:[NSString stringWithUTF8String: type]] UTF8String];
}
上記のコードは完全に機能します。関数内にobjective-cを持つc++クラスのc++関数。しかし、私がこれを行うとき:
void OSXSpecifics::printToConsole(<#const char *text#>) {
NSString *Text = [NSString stringWithUTF8String: text];
}
いくつかのエラーが発生します。主に:variable has incomplete type 'void
。私も取得しexpected primary expression before '<'token
ます。そしてまた興味深い:expected ';' after top level declarator
。これは、クラスのヘッダーファイルです。
#ifndef OSXSPECIFICS_h
#define OSXSPECIFICS_h
#include <string.h>
class OSXSpecifics
{
public:
static std::string GetOSXFilePath(const char* name, const char* type);
static void printToConsole(const char* text);
};
#endif // OSXSPECIFICS_h
xcodeがc++とObjectiveCのミキシングに夢中になっている理由は何ですか?