T
tuko
Hello everyone.
At the following snippet, at the commented line
the [this] pointer is valid? I mean the object bar is not
constructed yet. So after the contruction of the bar object,
the list foo::bars_, contain valid pointers? Is that
guarantee to work?
Suppose that no exception is thrown.
#include <list>
class bar;
class foo {
public:
std::list<bar *> bars_;
};
class bar {
public:
bar(foo *f);
};
bar::bar(foo *f) {
if (f) {
f->bars_.push_back(this); // The this pointer is valid?
}
}
int main () {
foo *f=new foo;
bar *br = new bar(f);
}
Many thanks for your time
At the following snippet, at the commented line
the [this] pointer is valid? I mean the object bar is not
constructed yet. So after the contruction of the bar object,
the list foo::bars_, contain valid pointers? Is that
guarantee to work?
Suppose that no exception is thrown.
#include <list>
class bar;
class foo {
public:
std::list<bar *> bars_;
};
class bar {
public:
bar(foo *f);
};
bar::bar(foo *f) {
if (f) {
f->bars_.push_back(this); // The this pointer is valid?
}
}
int main () {
foo *f=new foo;
bar *br = new bar(f);
}
Many thanks for your time