Carbon (AGL) or Cocoa?

DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #16
Vertizor Wrote:My understanding about Objective-C++ is that it lets you use C++ classes within Obj-C code. You can design and implement C++ classes within *.m files that normally are parsed by the Obj-C compiler. BUT... you can not use Obj-C classes in C++ code. For that reason, I gave up on Obj-C++ and chose to either go full C/C++ or full Obj-C.

I prefer C/C++ for its syntax and semantics. But since I can't use the NS* classes in pure C++ code, Obj-C++ is useless to me.
In ObjC++, you can mix C++ and ObjC code to your heart's desire. You cannot implement C++ stuff in .m files, you have to use .mm files. The major drawback of ObjC++ are the awfully long compile times.

You can use use ObjC classes in C++ code when using the ObjC++ language, but of course not in pure C++.

Also note that many of the NS* classes have CF* counterparts in CoreFoundation, which is a C API.
Quote this message in a reply
Vertizor
Unregistered
 
Post: #17
Is that something relatively new? (Mixing C++ code with Core Foundation and App Kit) I admit my impression is outdated, last time I looked into Obj-C++ was well over a year ago. But like I said, I gave up on it and found it faster to either accept Obj-C or use Carbon.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #18
ObjC++ resides in .mm files... they can contain both C++ and Objective C code, though there is (for example) no unification between C++ and ObjC classes. You can, however, have a field of a C++ object be an ObjC object, or vice versa.
Quote this message in a reply
webwarrior
Unregistered
 
Post: #19
Is there something special to get Objective-C++ compiled in Xcode? I started with an normal Cocoa Application. I added a custom view in Interface Builder and connected it with my wwOpenGLView class which is a subclass of NSOpenGLView. I implemented basic stuff, compiled it, and it worked perfectly. I had the following files:

main.m
wwOpenGLView.m
wwOpenGLView.h

I imported two files now called Demo.h and Demo.cpp (both are reall C++ files), and I'd like to have an instance variable in my wwOpenGLView which is of type Demo. I changed the filename of wwOpenGLView.m to wwOpenGLView.mm and I added the libstdc++.a to the frameworks. I include Demo.h in wwOpenGLView.h and I add "Demo *mydemo" as an instance variable.

When I'm trying to comile, it gives me numerous errors, the first one telling me that there is an error near the word "class" in Demo.h (I know that this file is perfectly well, as I used it a lot when I was coding with SDL, but to be sure, I cut out most of it). Other erros are "new" not found, "delete" not found. So for me it seems like Xcode treats the file as a normal Objective-C file and not as an Objective-C++ file. What am I doing wrong? That drives me mad :-(
Quote this message in a reply
webwarrior
Unregistered
 
Post: #20
It's working, a *really* stupid thing. Simply change the name from filename.m to filename.mm doesn't seem to change the type (but I should actually no? I mean, on Apple Dev site they say that a *.mm file is treated as Obj-C++ by default). I inspected the info panel of the wwOpenGLView.mm file and saw that its type still was sourcecode.c.objc Once I changed it into sourcecode.cpp.objcpp everything worked perfectly.

Did other users experience the same problem? Or have I done something wrong by just renaming? I thought the type depends on the name.

Another question: maybe more related to Xcode than to the subject of this thread...

I'm using the FMOD library for sound in my programs. They don't provide a framework, but just a simple libfmod.a file. Up to now I did all my development in Eclipse and compiled everything using a Makefile I wrote. How can I link this lib in Xcode now? Xcode is somewhat weird if one's not used to it.

Thx :-)
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #21
sounds like a crappy Xcode bug...

to use a .a file in Xcode, just drag it into your project, or use "add files".
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Carbon vs Cocoa? Jamie W 11 5,035 May 27, 2009 11:07 AM
Last Post: Ingemar
  is sdl+opengl slower than cocoa/carbon+opengl? Najdorf 9 4,846 Nov 16, 2005 09:45 PM
Last Post: WhatMeWorry
  Carbon vs Cocoa OpenGl Byron Clarke 2 2,862 May 31, 2005 05:47 PM
Last Post: maaaaark
  SDL, Cocoa or Carbon? Taxxodium 7 4,528 Jan 10, 2004 10:58 PM
Last Post: OneSadCookie