FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Architecture & Design
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
March 01, 2004

Strict Ownership in STL Containers

(Page 6 of 6)
March 04:

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());
}




    
    
        
Previous Page | 1 | 2 | 3 | 4 | 5 | 6
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK