-1

I have been given some C++ classes to incorporate into my Objective C project. I've never done this before, so I have to ask:

  1. Is there something special I need to do or can I just rename the .cpp to .mm?
  2. What about importing (or including) the .h file? Anything special I need to do there?

Just baby steps here. Thank you.

jstevenco
  • 2,913
  • 2
  • 25
  • 36
Patricia
  • 5,019
  • 14
  • 72
  • 152
  • Have you tried renaming files and including the .h and have it fail? – yan Oct 02 '13 at 20:03
  • Yes. In my interface, I get the following two errors: Missing context for method declaration and Expected method body. I think that is because of what is in the C++ header file, but I don't know much about C++. – Patricia Oct 02 '13 at 20:05
  • I think you have to rename almost every file in your project to `.mm` for this to work, otherwise the compiler just tries to compile using Objective-C instead of Objective-C++. – Ian Oct 02 '13 at 20:08
  • Every file that includes the C++ header will have to be switched over to Objective-C++. Remember how the C (and Objective-C and C++) build model works. – bames53 Oct 02 '13 at 20:09
  • @bames53 - Answer the question, so I can give you some points. Thank you very much. Your comment made it very clear what I needed to do. All the C++ classes could keep their .cpp extension. Only the Objective-C classes that import the C++ header files need the .mm extension. – Patricia Oct 02 '13 at 20:16

2 Answers2

1

See my answer to this question. Basically, the .mm convention is a nicety, not a necessity. If you use the File Inspector to set up the file types of the .h\.m\.cpp files correctly, you can get Objective-C to play nicely with C++ files without difficulty.

Community
  • 1
  • 1
jstevenco
  • 2,913
  • 2
  • 25
  • 36
1

Remember how the C build model works; It is the Objective-C files including C++ headers that must be switched over to Objective-C++.

bames53
  • 86,085
  • 15
  • 179
  • 244