GenericParser Parser?
, , , .
... boost:: function and boost:: lambda. , , - function ( ) . boost::function< void ()> reader = bind( &TextFile::read, reader );
.
class User
{
const boost::function< void ()>& reader;
public:
void setReader( const boost::function< void ()>& reader )
: reader(reader) {
}
};
, .h/.cpp.
, , (Comau-). "" 1 "" 2
@CiscoIPPhone Comment: The problem with the shared parser is that the class you are about to enter must also be a template.
template<class T>
class GenericParser
{
public:
GenericParser(T* p_reader) : reader(p_reader) { }
void StartParsing()
{
reader->Read();
}
private:
T* reader;
};
class Parser
{
public:
Parser( GenericParser<TextFileReader> p_reader) : reader(p_reader) { }
void StartParsing() {
reader->Read();
}
private:
GenericParser<RealParser> reader;
};
template<class T>
class Parser
{
public:
Parser( GenericParser<T> p_reader) : reader(p_reader) { }
void StartParsing() {
reader->Read();
}
private:
GenericParser<T> reader;
};
source
share