Lorry Astra
2009-08-06 12:30:05 UTC
Dear all,
I have a question in today's code review, here is my code example:
class A{
public:
A(B& b)
{....}
};
class B{
public:
B() : A(*this)
{....}
};
I think here exists a risk in class B constructor. Because I think when
constructor A is executed before constructon B ("B() : A(*this)"),
constructor A uses an object of class B as parameter. But I believe the
object of class B is not generated while constructor A running. So I think
"A(*this)" is a risk.
So I think if this code is like that, the executed sequence will be:
1. A(*this) -> A(B& b)
2. B()
Is that right? Are there any errors in my description?
Thanks.
Br,
Lorry
I have a question in today's code review, here is my code example:
class A{
public:
A(B& b)
{....}
};
class B{
public:
B() : A(*this)
{....}
};
I think here exists a risk in class B constructor. Because I think when
constructor A is executed before constructon B ("B() : A(*this)"),
constructor A uses an object of class B as parameter. But I believe the
object of class B is not generated while constructor A running. So I think
"A(*this)" is a risk.
So I think if this code is like that, the executed sequence will be:
1. A(*this) -> A(B& b)
2. B()
Is that right? Are there any errors in my description?
Thanks.
Br,
Lorry