• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Compile errors with Objective-C++ properties as STL/TR1 smart pointers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
      • From: Brian Bruinewoud <email@hidden>
  • Prev by Date: Re: Dynamically update drawRect
  • Next by Date: Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
  • Previous by thread: Re: dragging to trash folder problems
  • Next by thread: Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
  • Index(es):
    • Date
    • Thread