Re: warning: C++ constructors and destructors
Re: warning: C++ constructors and destructors
- Subject: Re: warning: C++ constructors and destructors
- From: Greg Parker <email@hidden>
- Date: Wed, 15 Feb 2006 17:37:56 -0800
email@hidden wrote:
I've got this warnings when compiling :
/Users/simon/Projets/Magn?to/SBObject/SBAudioFile.h:30: warning: type
`CAStreamBasicDescription' has a user-defined constructor
/Users/simon/Projets/Magn?to/SBObject/SBAudioFile.h:30: warning: C++
constructors and destructors will not be invoked for Objective-C
fields
My application works anyway, but does anyone know how to solve it?
Presumably you have something more or less like this:
class CAStreamBasicDescription {
public:
CAStreamBasicDescription() { /* initialize stuff here */ }
~CAStreamBasicDescription() { /* un-initialize stuff here */ }
};
@interface SBAudioFile : SBObject {
CAStreamBasicDescription desc;
}
@end
The warning is telling you that (1) when you allocate an instance of
SBAudioFile, the constructor for `desc` will not be called, and (2)
when you free an instance of SBAudioFile, the destructor for `desc`
will not be called. `desc` will be zero-filled at allocation like all
other Objective-C instance variables, but nothing else will happen.
Depending on the contents of the constructor and destructor, this may
be harmless. Alternatively, it may be a memory leak, or a subtle bug
waiting to hit when you least expect it.
There are several ways to fix this:
1. If you are compiling with gcc-4.0 and running on Mac OS X 10.4
(Tiger) and later, you can compile with `-fobjc-call-cxx-cdtors`. Then
desc's constructor will be called during +[SBAudioFile alloc], and the
destructor will be called after -[SBAudioFile dealloc]. There's an
Xcode build option that corresponds to this flag, but I don't remember
what it's called.
2. Remove the constructors and destructors for
CAStreamBasicDescription and its superclasses, if any. If you don't
care that they're not being called, you may not need them at all.
3. You can called the constructor yourself in SBAudioFile's designated
initializer, and the destructor in -[SBAudioFile dealloc].
4. You can change your instance variable to a pointer
`CAStreamBasicDescription *desc`, and use new and delete in
SBAudioFile's designated initializer and -dealloc methods.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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