Compile errors with Objective-C++ properties as STL/TR1 smart pointers
Compile errors with Objective-C++ properties as STL/TR1 smart pointers
- Subject: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
- From: Tron Thomas <email@hidden>
- Date: Sat, 26 Dec 2009 16:20:15 -0800
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_ptr<Value> 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 (email@hidden)
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:
This email sent to email@hidden