On Thu, May 6, 2010 at 2:19 AM, Barry Wark <barryw...@gmail.com> wrote: > I'm no C++ guru, so I'm hoping someone can help me by explaining why > the following gives a compiler error:
I'm no guru either, but my guess would be that the interaction between synthesized ivars and C++ templates is rocky territory. I avoid going down that path, declare the ivar as a pointer (with an #ifdef to declare it as a void* for ObjC client code) and create the object with new in +init. Here's a snippet from a random number generator class I wrote, that uses Boost's random module "under the hood": In SPRandom.h: #ifdef __cplusplus #import <boost/random.hpp> #endif typedef struct { int min; int max; } SPRandomRange; @interface SPRandom : NSObject { #ifdef __cplusplus boost::uniform_int<> *distribution; boost::variate_generator<boost::lagged_fibonacci607&, boost::uniform_int<> > *generator; #else void *distribution; void *generator; #endif } ... @end In SPRandom.m: static boost::lagged_fibonacci607 rng; @implementation SPRandom - (id) initWithRange:(SPRandomRange)range { self = [super init]; if (self) { distribution = new boost::uniform_int<>(range.min,range.max); generator = new boost::variate_generator<boost::lagged_fibonacci607&, boost::uniform_int<> >(rng, *distribution); } return self; } - (void) dealloc { delete generator; delete distribution; [super dealloc]; } @end sherm-- -- Cocoa programming in Perl: http://www.camelbones.org _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com