View Single Post
Old Jan 2nd, 2007, 6:54 AM   #7
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3 Soulstorm is on a distinguished road
I didn't try to learn C++ by replicating ObjC's features, or the other way around. It's just a game for me. I know Obj-C very well, believe me. But haven't you ever felt you want to do something just for the sake of doing it?

Anyway, thanks for the advice, and it never hurts asking, so I did. Besides, since I have never been involved with void pointers, it's a good opportunity to do so, even if that's not going to lead into a valid project. I'm 20 years old, I still have time to mess around a little bit.

EDIT:
Quote:
Objective C supports that more easily, as all types are derived from a base type (id). In C++, there is no universal base type.
Correct me if I'm wrong, but I believe ObjC classes derive from NSObject, not an object of type id. Some Cocoa classes do not even derive from that. And I don't think that NSArray rely on what you said to hold any type of class. I think it relies on the fact that none of the class the programmer creates is treated internally like C++ treats it's own classes, since all classes are created using pointers. The compiler knows what type of class you created when it sees it's name, but it actually allocates the memory manually (with the inherited -alloc function). So, an NSArray does not contain any object, but just pointers to classes, that have been manually allocated elsewhere. And that's why I believe this pattern can be simulated in C++.

It is simulated anyway into the CoreFoundation Framework by Apple, which, among other things, provides classes that behave like an NSArray.
__________________
Project::Soulstorm (personal homepage)

Last edited by Soulstorm; Jan 2nd, 2007 at 7:15 AM.
Soulstorm is offline   Reply With Quote