T
Tim Partridge
If I have an "add" method that adds a pointer to a foo to a private
std::list, should I define add like
1. void add( const foo &f ) { lst.push_back( &f ); }
to keep pointers out of my interface, or should I make it implicit that a
pointer is being added to the list, like so
2. void add( foo *f ) { lst.push_back( f ); }
Would the first method lead the user to believe that their foo is actually
being stored, potentially leading to a bad memory value in the list once
the foo is destroyed? Or is this discussion moot as long as I use pre and
post conditions?
Tim Partridge
std::list, should I define add like
1. void add( const foo &f ) { lst.push_back( &f ); }
to keep pointers out of my interface, or should I make it implicit that a
pointer is being added to the list, like so
2. void add( foo *f ) { lst.push_back( f ); }
Would the first method lead the user to believe that their foo is actually
being stored, potentially leading to a bad memory value in the list once
the foo is destroyed? Or is this discussion moot as long as I use pre and
post conditions?
Tim Partridge