0

I have a few classes I wrote to deal with numbers having units transparently as if they were just ints or floats. In a nutshell:

SI_Term speed(4, "mph");
SI_Term distance(10000, "feet");
SI_Term time = distance / speed;
std::cout<<time.string();

and all the major operators are overloaded to work this way. Took a quite a bit of work so I would like to use the C++ classes in my ObjC iPhone app. I tried adding them with .h and .mm extensions to my xcode project, but it doesn't seem to be treating them as C++ files. (Won't find any of the STL headers, syntax errors anywhere I declare a class or anything).

New Info: Tried .mm and .h extensions, errors: in a .h file: namespace DA and just about everything else involving c++ code (about 40 errors all this message) gives me expected '=', ',', ';', 'asm' or '__attribute__' before ':' token

I also get *: No such file or directory for all instances of #include <*> throughout the c++ files.

I'm sure its some kind of simple fix but .mm and .h wasn't enough.

Update: Found that copying and pasting source code into new files seems to work. The mm file (or the cpp file) compiles. The h file doesn't work though, it throws the above mentioned error at any occurrence of c++ specific code.

Thanks!

Hagelin
  • 16,440
  • 5
  • 29
  • 37
Alex Gosselin
  • 2,942
  • 21
  • 37
  • 1
    possible duplicate of [Use C++ with Objective-C in XCode](http://stackoverflow.com/questions/2683101/use-c-with-objective-c-in-xcode) – Jesse Beder May 15 '11 at 01:43
  • Please provide more detail; exact errors returned, etc. – Andrew Pouliot May 15 '11 at 02:41
  • @Jesse_Beder I agree it is almost the same question, but the platform is Xcode4 now which seems to have enough differences that I couldn't use the correct answer from that question to resolve my problem. – Alex Gosselin May 15 '11 at 02:47

2 Answers2

2

You are probably including (or importing) your h file in one of your .m files. Those need to be renamed to .mm too.

In the end you'll probably name all .m fikes to .mm. And by the way, the cpp files, can simply remain cpp. No reason to rename them.

Kris Van Bael
  • 2,842
  • 1
  • 18
  • 19
1

Not knowing exactly what the errors you're getting are, rather than adding your files with a .hpp and .cpp extension to your project, I would change the extension of the header files to just .h, and the extension to your .cpp files to either .mm or .M so that Xcode recognizes them as Objective-C++ files, and compiles them appropriately.

Jason
  • 31,834
  • 7
  • 59
  • 78