I am working on a cross platform c++ app. On the mac version I need to use a little bit of cocoa in obj-c. So I have made a class called OSXSpecifics and it has the .mm file extension and a c++ header like the rest of the app.
std::string OSXSpecifics::GetOSXFilePath(const char *name, const char *type) {
return [[[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String: name]
ofType:[NSString stringWithUTF8String: type]] UTF8String];
}
The above code works absolutely perfect. A c++ function in a c++ class with objective-c inside the function. But when I do this:
void OSXSpecifics::printToConsole(<#const char *text#>) {
NSString *Text = [NSString stringWithUTF8String: text];
}
I get a couple of errors. Mainly: variable has incomplete type 'void. I also get expected primary expression before '<'token. And also of interest: expected ';' after top level declarator.
This is the header file for the class:
#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
Any idea’s why xcode is freaking out about c++ and objective c mixing?
I think
<#const char *text#>should beconst char *text.The
<#and#>were put there by Xcode’s autocomplete system and should be removed.