开发者

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

开发者 https://www.devze.com 2023-02-02 19:28 出处:网络
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 Do开发者_C百科nal

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 Do开发者_C百科nald.h. Is there a way to do this?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消