Re: vtables in objc++
Re: vtables in objc++
- Subject: Re: vtables in objc++
- From: Tobias Sargeant <email@hidden>
- Date: Tue, 25 Feb 2003 14:16:55 +1100
On Monday, Feb 24, 2003, at 19:30 Australia/Melbourne, Oscar Morales
Vivs wrote:
I can't comment on your error (are you sure using the .mm suffix and
all?) I do have some advice, having done some Objective-C coding.
Remember that Objective-C (and by extension Objective-C++) zeroes all
instance variables when creating an object. That's why you can't use
C++ objects with virtual functions, as the vtable pointer won't get
initialized.
Not quite. zeroing memory first is fine. Not calling constructors isn't.
Basically, the way obj-c allocates memory means that you can't use C++
objects as
obj-c object members, unless you explicitly call the constructor. This
is because
the obj-c [alloc] message just allocates (zeroed) memory for you, and
doesn't call
constructors. Similarly, [dealloc] won't call any destructors. You can,
however,
use placement new (and an explicit call to the destructor):
@interface Foo
{
std::vector<int> foo;
}
- (id) init;
- (void) dealloc;
@end
@implementation Foo
- (id)
init
{
self = [super init]
new (&foo) std::vector<int>();
}
- (void)
dealloc
{
foo.~vector();
}
@end
i just encountered this:
ld: Undefined symbols:
vtable for CustomControlElement
Often, a missing vtable is results when a pure virtual function is
declared but not implemented. This can happen implicitly with
pure virtual destructors (if you delcare a destructor pure, you
still have to provide an implementation).
Toby.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.