, , o Foo, o.
-, , , o Foo.
, :
Foo* y = &x;
o->setFoo(y);
"x" - , , , , .
, , o Bar
1 Bar Foo - .. Foo.
, - , Foo
, Foo ,
{
std::auto_ptr<Bar> o = new Bar();
o->setFoo(new Foo());
o->DoStuff();
}
{
std::auto_ptr<Foo> y = new Foo(...);
y->config();
o->setFoo(y.release());
}
2 Foo - .. Foo
Bar Foo, , , Bar Foo
2.1 , Bar
Bar Foo
{
Foo y;
std::auto_ptr<Bar> o = new Bar();
o->setFoo(&y);
o->DoStuff();
}
2.2 , Bar
SomeFunc( Foo *y );
{
std::auto_ptr<Bar> o = new Bar();
o->setFoo(y);
o->DoStuff();
}
{
Foo y;
SomeFunc( &y );
}
2.3 suggests that you have a panel that will be used in different areas
std::auto_ptr<Foo> y = new Foo();
std::auto_ptr<Bar> o = new Bar();
{
o->setFoo(y.get());
}
{
o->DoStuff();
}
and then you can give other examples based on how you work with Foo for several bars, including containers, etc.
source
share