I wrote the next code and if the comment line will be removed it will work. But i did the same with ref to int and everything was nice even without constructor.
#include <iostream>
struct B;
struct A
{
B& b_;
//A(B& b):b_(b){}
};
struct B:A
{
int x = 5;
B():A(*this)
{
}
};
int main()
{
B b;
std::cout<<b.b_.x<<std::endl;
}
https://godbolt.org/z/7hd7oaPon
New contributor
7Zon2 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7