Compile errors with Objective-C++ properties as STL/TR1 smart pointers
I'm running into a issue using STL/TR1 smart pointers with Objective-C++ properties that I think is a bug, and I wanted to get some feedback before I submitted any bug report. The following code: #import Cocoa/Cocoa.h #import tr1/memory class Value { public: explicit Value(int amount) : m_amount(amount){} int GetAmount() const { return m_amount; } private: int m_amount; }; typedef std::tr1::shared_ptrValue ValuePtr; @interface ValueUser : NSObject { @private ValuePtr* _valuePtr; } - (id)initWithValue:(ValuePtr)valuePtr; @property ValuePtr value; @end @implementation ValueUser - (id)initWithValue:(ValuePtr)valuePtr { self = [super init]; _valuePtr = new ValuePtr(valuePtr); return self; } - (void)setValue:(ValuePtr)valuePtr { *_valuePtr = valuePtr; } - (ValuePtr)value { return *_valuePtr; } - (void)dealloc { delete _valuePtr; [super dealloc]; } @end int main() { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; ValuePtr valuePtr(new Value(42)); ValueUser* valueUser = [[ValueUser alloc] initWithValue:valuePtr]; ::NSLog(@The value's amount is %d, valueUser.value-GetAmount()); [valueUser release]; [pool release]; return 0; } will produce these errors on the line in the main function containing the NSLog call: error: lvalue required as unary ‘’ operand error: base operand of ‘-’ has non-pointer type ‘ValuePtr’ If I replace the line with: ::NSLog(@The value's amount is %d, [valueUser value]-GetAmount()); Everything compiles successfully. What is the reason the '.' syntax will not work in this instance? ___ 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
Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
It's probably just a parsing thing, have you tried: ::NSLog(@The value's amount is %d, (valueUser.value)-GetAmount()); ? On 27/12/2009, at 11:20 , Tron Thomas wrote: I'm running into a issue using STL/TR1 smart pointers with Objective-C++ properties that I think is a bug, and I wanted to get some feedback before I submitted any bug report. The following code: #import Cocoa/Cocoa.h #import tr1/memory class Value { public: explicit Value(int amount) : m_amount(amount){} int GetAmount() const { return m_amount; } private: int m_amount; }; typedef std::tr1::shared_ptrValue ValuePtr; @interface ValueUser : NSObject { @private ValuePtr* _valuePtr; } - (id)initWithValue:(ValuePtr)valuePtr; @property ValuePtr value; @end @implementation ValueUser - (id)initWithValue:(ValuePtr)valuePtr { self = [super init]; _valuePtr = new ValuePtr(valuePtr); return self; } - (void)setValue:(ValuePtr)valuePtr { *_valuePtr = valuePtr; } - (ValuePtr)value { return *_valuePtr; } - (void)dealloc { delete _valuePtr; [super dealloc]; } @end int main() { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; ValuePtr valuePtr(new Value(42)); ValueUser* valueUser = [[ValueUser alloc] initWithValue:valuePtr]; ::NSLog(@The value's amount is %d, valueUser.value-GetAmount()); [valueUser release]; [pool release]; return 0; } will produce these errors on the line in the main function containing the NSLog call: error: lvalue required as unary ‘’ operand error: base operand of ‘-’ has non-pointer type ‘ValuePtr’ If I replace the line with: ::NSLog(@The value's amount is %d, [valueUser value]-GetAmount()); Everything compiles successfully. What is the reason the '.' syntax will not work in this instance? ___ 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/brian%40darknova.com This email sent to br...@darknova.com ___ 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
Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
I tried (valueUser.value)-GetAmount()) and I still get the same errors. Date: Sun, 27 Dec 2009 11:47:35 +1100 From: Brian Bruinewoudbr...@darknova.com Subject: Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers To: undisclosed-recipients: ; Cc: cocoa-dev@lists.apple.com Message-ID:bff7a0e2-640d-4407-bcde-38fc06046...@darknova.com Content-Type: text/plain; charset=windows-1252 It's probably just a parsing thing, have you tried: ::NSLog(@The value's amount is %d, (valueUser.value)-GetAmount()); ___ 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