Re: using C++ with Cocoa
Re: using C++ with Cocoa
- Subject: Re: using C++ with Cocoa
- From: Kaelin Colclasure <email@hidden>
- Date: Thu, 24 May 2007 10:35:45 -0700
If you *do* use these magic methods, you'll need to implement them to
include retains on all of your ObjC instance pointers... And of
course, make sure you have a destructor that releases them.
ObjC++ is an important enabling technology, but it requires a
thorough understanding of both ObjC+Cocoa and C++ to use it
effectively. And in my experience it increases compilation times by
about an order of magnitude... My recommendation is to encyst your C+
+ code in as few ObjC++ source files as you can manage, and do the
bulk of your project in ObjC when possible.
-- Kaelin
On May 24, 2007, at 8:20 AM, Oscar Morales Vivo wrote:
It's a warning you can safely ignore if you know what you're doing.
If you just want to kill the warnings and you're not going to use
all those 'magic' methods, something like the following would be
advised in your C++ class:
class MyCPPClass
{
public:
[...]
protected:
[...]
private:
MyObjCClass* ObjCDataMember;
// Undefined methods.
MyCPPClass(const MyCPPClass&);
MyCPPClass& operator=(const MyCPPClass&);
};
Don't define them (the linker won't complain since it's a
sanctioned technique for specifying that you want no stinking copy
constructor or assignment operator for your class).
You probably can find more information about this technique
elsewhere, it's pretty common and certainly not unique to dealing
with Obj-C++.
On May 24, 2007, at 9:25 AM, Frank Weinstock wrote:
I have a Cocoa project going and, for various reasons, need to add
a number of C++ class (and I'm a newbie with C++). Those classes
need to refer to Cocoa objects, which of course come in the form
of pointers. But when I use pointers as data members in C++,
Xcode gives me the warning (actually 3 warnings): "class ClassName
has pointer data members but does not override 'ClassName(const
ClassName&)' or 'operator= (const ClassName&)' " (where ClassName
is, of course, the class I am defining). I know how to override
ClassName(const ClassName&), but I have no idea how to override
operator= (const ClassName&)', or what that even means in this
context.
I know the whole thing could be avoided by using C++ references
instead of pointers, but in this case I can't do that because the
data is not available when the class is first created. Also, I
know that warnings are not the end of the world, but I'd rather
get rid of them if possible...
Thanks for any ideas!
Best,
Frank
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden