Re: Cocoa & STL
Re: Cocoa & STL
- Subject: Re: Cocoa & STL
- From: "John C. Daub" <email@hidden>
- Date: Thu, 31 Mar 2005 08:01:15 -0600
on 3/31/05 4:30 AM, Sebastian Vollmer at email@hidden wrote:
> Is there any possibility to use STL with Cocoa. I tried to use vector in a
> Document-based Application. I typed #include <vector>, but I get the error
> "vector: No such file or directory".
> How can I use vector with Cocoa?
Yes you can, but it kinda depends what you need.
First, recall that Cocoa's main language is Objective C, and STL is C++. So,
you are mixing languages. If you keep them in separate implementation files,
then your Cocoa/ObjC sources will end in .m and your C++ source files would
end in .cpp. But, if you want to mix the two, then you're using Objective
C++ and thus your source file must have a .mm filename extension. That may
be your problem here.
You do have to keep in mind that you are mixing languages (ObjC, C++) and
using a new language (ObjC++) and thus you have to play according to the
rules and restrictions of each language. There is information about
Objective C++ in Apple's documentation. It's not long, it's not much, but it
does let you know what sort of world you're playing in and you'd be wise to
check out this documentation.
Another thing about using STL and Cocoa is that STL's containers aren't
savvy to Cocoa objects like Cocoa containers are. Thus, sometimes it may
suit you better to use an NSArray to contain your NSObject-based objects
than trying to stuff them into a std::vector. Just be mindful of what sorts
of things you're trying to contain and pick the correct container type for
it.
One cool thing tho that Allan Odgaard did was write CocoaSTL:
<http://www.top-house.dk/~aae0030/cocoastl/>
>From the page: "Since I was missing features from the standard C++ library
when working with various aspects of Cocoa, I decided to write STL
conforming iterators for some of the Cocoa Foundation classes."
It's nifty stuff. :-)
Hope this helps.
--
John C. Daub }:-)>=
<mailto:email@hidden> <http://www.hsoi.com/>
"Virtue does not come from money, but rather from virtue
comes money, and all other things good to man." - Socrates
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Cocoa & STL (From: "Sebastian Vollmer" <email@hidden>) |