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

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

Strict Ownership in STL Containers

(Page 3 of 6)
March 04:

Listing 2: Using DynObj.

// Foo.hh
class Bar;
class Foo {
    public:
        Foo();
        void doSomething() const;
        void getBar(DynObj<Bar>&);
    private:
        DynObj<Bar> _bar;
};
// Foo.cc
#include "Foo.hh"
#include "Bar.hh"
Foo::Foo(): _bar(new Bar) {}
void Foo::doSomething() const { _bar().constMethod(); }
void Foo::getBar(DynObj<Bar>& bar) {_bar.giveAway(bar);}
// Bar.hh
class Bar {
    public:
        Bar() {}
        void constMethod() const {}
};
// main.cc
int main() {
    Foo foo; 
    foo.doSomething();
    DynObj<Bar> bar;
    foo.getBar(bar);
    bar().constMethod();
}




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



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK