View Full Version : Apple newbie can't even get off the ground
GreatBigBore
2006.04.24, 08:48 PM
I've managed to compile and run Apple's Cocoa sample application, "CurrencyConverter". Now I want to start playing with it a bit, but I'd like to use C++ for now, rather than dealing with the complication of learning a new language. I have an example app from Apple, "SimplePlayThru", which uses both Cocoa and C++ with no problem, but I can't figure out how to add C++ code to CurrencyConverter, although I've done all the same things (as far as I can tell) as SimplePlayThru. The compiler acts like it doesn't recognize the word "class". Is this a mistake that everyone makes when learning how to write Apple code?
When the compiler sees:
class RobObject
{
public:
RobObject();
~RobObject();
};
It says, "parse error before 'RobObject'", on the first line.
OneSadCookie
2006.04.24, 08:58 PM
Make sure that you've put the C++ code into a file that the compiler will recognize as C++ -- .cpp is the most common extension. If you need to mix ObjC and C++, you'll need to use .mm. Remember that code in header files is effectively in every file it's included in, so it needs to compile as all those languages.
Accolon
2006.04.25, 06:55 AM
I guess OneSadCookie's advice will help you, but why don't you want to use ObjC? It has advantages (and of course) disadvantages, but ObjC is really a small superset of C and you'll learn it in less than an afternoon. Chapter 3 in Hillegass' book i.e. teaches you all you'll need to beginn with and I guess there are 'quicker' ways on the net to dig in ObjC than Apple's own big ObjC book.
IMO, the heavy part is actually learning Cocoa, not ObjC...
GreatBigBore
2006.04.25, 07:55 AM
Thanks, OneSadCookie. I changed .m to .mm, and everything works great. Thanks so much. Do you know of any good samples of Cocoa applications that have lots of C++ in them?
Taxxodium
2006.04.25, 08:22 AM
Do you know of any good samples of Cocoa applications that have lots of C++ in them?
There are quite a lot of them, including Safari (the WebKit framework is C++ I believe). The list usually contains games but there other apps too.
If you mean sample code, take a look at this (http://developer.apple.com/samplecode/Cocoa_With_Carbon_or_CPP/Cocoa_With_Carbon_or_CPP.html)
akb825
2006.04.25, 11:17 AM
My program Fractographer (http://www.akb825.com/fractographer.php) is written with Cocoa contains a lot of C++, and the source is also available.
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.