This is an old question to which I don't remember the answer. A quick few searches didn't clarify. Suppose I have the option of building functionality into an object or having it done to the object. I recall the latter being preferable in this type of circumstance, and std::string being made a negative example. Why?
Code:
//minimal container of a 2-dimensional array, or whatever.
template<class T>
class grid
{
public:
enum print_mode { text, binary }
grid(unsigned w, unsigned h);
T & operator()(unsigned x, unsigned y);
const T & operator()(unsigned x, unsigned y) const;
const unsigned width() const;
const unsigned height() const;
//should it be:
void print_to_file(const std::string & path, print_mode m);
~grid();
protected:
//whatever
};
//or should it be:
template<class T>
void print_to_file(const & grid<T> g, const std::string & path, grid<T>::print_mode m);
//I suppose the second method would move enum print_mode outside of grid, too.