Boost logo

Boost Users :

Subject: Re: [Boost-users] make member functions (in)accessible
From: Alan M. Carroll (amc_at_[hidden])
Date: 2009-02-26 12:44:03


At 10:11 AM 2/26/2009, you wrote:
>AMDG
>Stefan Funck wrote:
>>so I may do:
>>
>>A a;
>>a.propA.get();
>>a.propA.set(0.5);
>>a.propB.get();
>>
>>but NOT:
>>
>>a.propB.set(1);
>>
>>because propB was defined with Writable=false. BUT, from within class A, I would
>>like to do
>>
>>propB.set(1);
>>
>>because otherwise this property is useless. (How) can this be achieved (with boost)?
>>
>
>These two cases are indistinguishable.

Are they? While we seem to have wandered off the Boost territories, consider this: If B (== typeof(propB)) were defined effectively as

class B {
public: void get(...);
private: void set(...);
friend class A;
};

would that not have the effect desired? Conceptually you could use the CRTP pattern to mix A in to the instantiation of propB so that only A was a friend.

I don't think you can do this in real life with templates because gcc does not allow declaring template parameters as friends
(e.g., this does not compile)

template < typename T > class X { friend T; };


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net