Search code examples
objective-cincludeobjective-c++

Objective C, C++, Including two files with the same class name


I have an Objective C Class called Donald, I also have a C++ class called Donald in a static library that I would like to use in the same project. They both have a header file called Donald.h. Is there a way to do this?


Solution

  • You can include both header files by specifying a bit more of the path e.g.

    #import "staticlibraryheaders/Donald.h"
    #import "Donald.h"
    

    However, you might find that the code won't compile since you are declaring two types both called Donald. If the compiler sees:

    Donald* duck;
    

    How does it know to type duck as a pointer to an instance of the C++ class or the Objective-C class? You might be able to fix that if the C++ class is in a C++ namespace. However, that hits the limit of my C++ knowledge.