may help you . Short answer: There is no undefined behavior involved. The behavior you see is: The expression &A::a is an attempt to obtain a pointer to member pointing to member a of class A. If a is protected in A, this expression only passes access checks within class A (or friends of A). In a class B derived from A, you can get the same pointer to member only via the expression &B::a (note that the type of this expression will still be int A::*). So: if A::a is protected in A, the expression &A::a is not allowed in a member function of derived class B. This is your compiler error. if A::a is public in A, this expression is valid, producing a pointer to memeber. Streaming a pointer to member to an ostream, for example using cout << &A::a will print 1. This results from invoking ostream::operator << (bool). You can use the boolalpha manipulator to see that this is indeed the chosen overload: cout << boolalpha << &A::a will print true. If you use the modified expression &(A::a) or simply &a, no pointer to member is formed. Here the address of member a of the current object (i.e the same as &(this->a)) is taken, which is a regular pointer to int. This access to a protected member of a base class subobject of *this is valid, so that variant can be used even if a is protected in A.
This might help you Dont instantiate a seperate parent class, it will be instantiated as part of instantiating the child class. Also pass the object to the child instantiation and create a __construct() method and pass the parameter on to it.
class Child extends Parent
public function doStuff()
public function control()
//$parent = new Parent(new Object($variable));
$child = new Child(new Object($variable)); // line 25
How can I access member variables of a vector of objects that is a member variable from a class?