Back to list
Views:   2.6K
Replies:  0
Archived

Virtual + Template Method pattern: brilliant solution needed

I have the same implementation for 2 methods, they both insert argument to a text file.

void WriteToFile( double content) //for double
{    
streamFile << content;    
streamFile << flush;
}

void WriteToFile( int content) //for integer
{    
streamFile << content;    
streamFile << flush;
}  

The implementation is same, therefore I merge them to a template method:

template < class T>
void WriteToFile(T content)
{    
streamFile << content;    
streamFile << flush;
}  

But the WriteToFile() method should be virtual.Is there a design-pattern expert's trick to deal with it?

Dev T K, Sep 09, 2014


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.3.0