Zombie Outhouse Development Part 3
Zombie Outhouse Development Part 3: Converting from C# to C++
While the official programming language for the iPhone is Objective-C, you can use C/C++ within it. I prefer to work in C++ and try to avoid Objective-C at all costs.
To take the path from C# to C++ I used Tangible Software’s Instant C++ software. The conversion of the files was fairly quick but that was the easy part.
There was a lot of manual work in cleaning up the converted files. I removed all namespace references and had to make sure the classes compiled cleanly. I also had to recreate a lot of the core XNA classes/structs such as Rectangle, Color, Point, etc. I already had some of those classes converted a year ago for a previous test when I wanted to keep the API very similar to XNA.
Some issues to keep in mind when writing C# code that you plan to convert to C++:
Delegates – there is no built in support for delegates in C++ but there are a few solutions using libraries such as Boost. I decided to use a common base class and a standard virtual function pointer and just store pointers to the objects and their callback functions as my “delegate” pointer to keep things simple for now.
ArrayList vs List – Avoid ArrayList collections and use List collections which convert fairly cleanly to std::vector.