2

I'm working on an iPad app and I've been provided the header files for a custom view (which I cannot change). In the header file (there is no .m or .mm file with it), there's a namespace declaration:

namespace fooUI
{
    class Foo;
}

I'm trying to create a view of this class's type, so I make the UIView in XCode and then make an outlet for it in my view controller. When adding the header file in the ViewController.h file, I get an 'unknown type name namespace' error (followed by others, presumably related to this one). Any ideas on how to get around this?

1 Answer 1

6

You're compiling your code as Objective-C, not as Objective-C++. Change the extension of the file you're building to .mm, or add the -x objective-c++ flag.

Sign up to request clarification or add additional context in comments.

7 Comments

Hi there, the header file I'm including doesn't have a corresponding .m or .mm file, and the ViewController file is already at .mm, where would the -x objective-c++ flag go?
Then some other file you're building is including that header. What file does it say it's building when you get the error?
The XCode UI indicates that it's the view controller header. If I remove the header and change the type declaration, the issue goes away. Granted, that's not what I'm looking for, I need to be able to use this header :)
Yeah, you can't import that header into anything other than a C++ context. Wrap the import in an #ifdef __cplusplus
Headers don't get built directly. Some implementation file is getting built, and it (either directly or indirectly) includes that C++ header.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.