Listing 5: Specifying an extra parameter at declaration time.
struct Foo {
virtual void constMethod() const = 0;
virtual ~Foo() {}
};
struct DerFoo: Foo {
virtual void constMethod() const {}
};
int main() {
// instantiate list
typedef DynObj<Foo>::InValueContainer DOFoo;
std::list<DOFoo> foos;
// add two new DAO's
foos.push_back( dynObj(new DerFoo) );
foos.push_back( dynObj(new DerFoo) );
// add a DAO from a DynObj
DynObj<Foo> foo(new DerFoo);
foos.push_back( foo.giveAway() );
assert(foo.isNull()); // true
// xfer DAO from head of list
DynObj<const Foo> foo2( foos.begin()->giveAway() );
assert(foos.begin()->isNull()); // true
foo2().constMethod();
// erase first and second items
foos.erase(foos.begin());
foos.erase(foos.begin());
}