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 (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

Reply via email to