I have a class (C) with a member class (B) which tracks a third class (A). What's the proper syntax to call the public member functions of A via C and B? Or did I screw up my pointers?
#include <iostream>
class A
{
public:
void Hello() const {std::cout<<"World."<<std::endl;};
};
class B
{
const A* aa; // Pointer can change, data cannot.
public:
const A* *const aaa; // Pointer and pointed value are const.
B() : aaa{&aa} {};
void SetPointerToA(const A& aRef) {aa = &aRef;};
};
class C
{
B b;
public:
B* bb; // Provide access to public members of B.
C() : bb{&b} {};
};
int main()
{
A aTop;
C c;
c.bb->SetPointerToA(aTop); // Tell c.b to modify itself. No problems here.
c.bb->aaa->Hello(); // <==== Does not compile.
return 0;
}
gcc 5.2.0 complains about the call to Hello() :
error: request for member 'A:: Hello' in '*(const A**)c.C::bb->B::aaa',
which is of pointer type 'const A*' (maybe you meant to use '->' ?)