我有一个名为 Property 的类(来自外部库 == 无法修改),它具有私有重载 & 运算符。我在另一个类中使用这个类作为属性,并且(出于理智的原因)我想通过 Get 方法返回对该属性的引用。但是,我遇到了无法处理的“无法访问在类中声明的私有成员”错误。有没有办法绕过它 - 不公开财产。
// 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;
}
};