views:

29

answers:

1

I got a class called Property (from external library == cannot be modified) that has private overloaded & operator. I use this class in another class as a property and (for sanity reasons) I'd like to return a reference to this property through the Get method. However I got the 'cannot access private member declared in class' error I cannot handle. Is there a way to walk around it - without making the Property public public.

// Some external class.
class Property
{
    Property*   operator&() const;
};

class MyClass
{
protected:
    Property m_Property;

public:

    // error C2248: 'Property::operator &' : cannot access private member declared in class 'Property'
    const Property& GetProperty() const
    {
        return *& this->m_Property;
    }
};
+2  A: 

I may be missing something, but why not simply say:

const Property& GetProperty() const
{
  return this->m_Property;
}

The fact that the operator& is private pretty clearly indicates that you are not supposed to call it.

anon
You are right, of course. Too much coffee I suppose;) Thank you.
mslaf