#include <iostream>
class FooParent
{
public:
FooParent(int* new_p_bar)
{
p_bar = new_p_bar;
}
public:
int* p_bar;
};
class FooChild : public FooParent
{
public:
int bar;
public:
FooChild(int new_x)
:FooParent(&bar)
,bar(new_x) \\ point of concern
{}
};
int main()
{
FooChild foo(8);
std::cout << foo.bar << std::endl;
}
The above example works as I want it to .i.e. link the pointer p_bar
to bar
. However, my concern is that I am pointing to a member whose constructor is not yet called.
Is this code valid, or does the standard have something to say about it. If not what is the alternative.
NOTE: In my application bar
is an Object Bar
(not int
), does this have any implications?