L
LuB
Bruce Sutter talks about this a bit - but I can't remember where. When
is it safe to use an object or reference to an object. When does it
have an accessible address?
Specifically, I think it has to pass out of the out initialization
stage ... but I can't remember exactly. Can anyone clarify?
Safety aside, is this undefined - passing B to A's ctor before B has
completed initialization?
Thanks in advance,
-Luther
/////////////////////////////////////////////////////
#include <iostream>
template<typename BType>
class A
{
public:
A(const BType& b) : b_(b) { std::cout << "A ctor" << std::endl; }
private:
const BType& b_;
};
class B
{
public:
B() : a_(*this) { std::cout << "B ctor" << std::endl; }
private:
const A<B>& a_;
};
int
main(int argc, char** argv)
{
B b;
std::cout << "hello world" << std::endl;
}
is it safe to use an object or reference to an object. When does it
have an accessible address?
Specifically, I think it has to pass out of the out initialization
stage ... but I can't remember exactly. Can anyone clarify?
Safety aside, is this undefined - passing B to A's ctor before B has
completed initialization?
Thanks in advance,
-Luther
/////////////////////////////////////////////////////
#include <iostream>
template<typename BType>
class A
{
public:
A(const BType& b) : b_(b) { std::cout << "A ctor" << std::endl; }
private:
const BType& b_;
};
class B
{
public:
B() : a_(*this) { std::cout << "B ctor" << std::endl; }
private:
const A<B>& a_;
};
int
main(int argc, char** argv)
{
B b;
std::cout << "hello world" << std::endl;
}