This would be trivial but it comes with a serious catch - I can't edit the Unrelated or Friend class. I can't seem to access a private data member despite the friend relationship between the classes. Code:
http://pastie.org/613042
class UnrelatedClass
{
...
private:
friend class FriendClass;
float m_fNumber;
}
class FriendClass
{
public:
CHandle<UnrelatedClass> m_hUnrelatedClass;
void Bar();
}
class DerivedClass : public FriendClass
{
public:
...
void Foo();
...
}
void FriendClass::Bar()
{
m_hUnrelatedClass->m_fNumber = 2.0; // no error
}
void DerivedClass::Foo()
{
...
FriendClass *friendClass = static_cast<FriendClass *>( this );
friendClass->m_hUnrelatedClass->m_fNumber = 2.0; // produces error
...
}
// error C2248: 'UnrelatedClass::m_fNumber' : cannot access private member declared in class 'UnrelatedClass'
I don't understand how the compiler can tell the difference between being in the class and just have it accessed from an object. Is there anyway around this WITHOUT altering the FriendClass or UnrelatedClass? I very much appreciate your thoughts on this.