• 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
Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers


  • Subject: Re: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
  • From: Brian Bruinewoud <email@hidden>
  • Date: Sun, 27 Dec 2009 11:47:35 +1100

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

_______________________________________________

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

References: 
 >Compile errors with Objective-C++ properties as STL/TR1 smart pointers (From: Tron Thomas <email@hidden>)

  • Prev by Date: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
  • Next by Date: Re: UITextfield print to NSLog
  • Previous by thread: Compile errors with Objective-C++ properties as STL/TR1 smart pointers
  • Next by thread: [iPhone] Refreshing a UITableView in a UINavigationController...
  • Index(es):
    • Date
    • Thread