« Airport Extreme HD SharingAirport Extreme Update »

C++ Support in Objective-C

02/28/07

Permalink 10:09:16 am, by rekle Email , 205 words   English (US)
Categories: Cocoa

C++ Support in Objective-C

Ok, this truly sucks.

Last night, I was playing with Objective C. I had written an O-C class and tried to include a C++ class as a member variable of the O-C class. Now, you would think this would be possible, since you can create Objective-C++ classes that take advantage of certain C++ features. Apparently, this support of C++ in Objective-C is incomplete at best. I discovered that when I added that C++ class as a member variable, it compiled, but it gave me a warning telling me that the constructor and destructor of that member class would not be called! If the constructor and destructor don't get called, C++ classes are basically useless! What else won't get called on the C++ class in this case? This really sucks. This means that I had to basically rewrite that C++ class as a full Objective-C class in order to use it properly.

This, in my opinion is a glaring hole in the current implementation of Objective-C. It seems inconceivable to me that you can easily include any C code you want, but only certain parts of C++ work in Objective-C. I really hope they fix this in Objective-C 2.0, that is coming Real Soon Now, in Leopard!

2 comments

Comment from: Chinmoy [Visitor] Email
ChinmoyI tried out some third-party code that used pointers to C++ objects inside an Objective-C class before and it seemed to work fine. Here is the link: http://ccrma.stanford.edu/courses/120/lectures/05/tutorial.html
04/04/07 @ 18:37
Comment from: rekle [Member] Email
rekleThe problem isn't calling C++ objects from O-C. That works. The problem is that if you have an O-C object with a C++ object as a member variable, the constructor and destructor will not be called in that case. That is the major problem I found.
04/04/07 @ 19:54
February 2012
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29        
Copyright © 2005 - 2011, Rick Ekle

Comments? Contact me at rick@ekle.us or visit me on Twitter at @rekle

Search

XML Feeds

User tools

powered by b2evolution free blog software