Thanks a lot, again. ;-)
This is the working code now.
#include <string>
#include <sstream>
#include
#include <vector>
#include
#include
#include <iostream>
class Base {
public:
virtual std::string to_String ( boost::uint32_t indent ) = 0;
};
class A : public Base {
public:
A ( boost::uint32_t value )
: m_value ( value )
{}
virtual std::string to_String ( boost::uint32_t indent )
{
std::stringstream output;
for ( boost::uint32_t i = 0; i < indent; i++ )
{
output << " ";
}
output << m_value;
return output.str();
}
private:
boost::uint32_t m_value;
};
class D : public Base {
public:
D ( boost::uint32_t value )
: m_value ( value )
{}
virtual std::string to_String ( boost::uint32_t indent )
{
std::stringstream output;
for ( boost::uint32_t i = 0; i < indent; i++ )
{
output << " ";
}
output << m_value;
return output.str();
}
private:
boost::uint32_t m_value;
};
void print( const std::string& s )
{
std::cout << s;
}
int main ( int, char** )
{
typedef boost::shared_ptr<A> A_ptr_t;
typedef boost::shared_ptr<D> D_ptr_t;
typedef std::vector < boost::shared_ptr<Base> > Data_t;
Data_t m_data;
A_ptr_t a ( new A ( 50 ) );
D_ptr_t d ( new D ( 30 ) );
m_data.push_back ( a );
m_data.push_back ( d );
boost::uint32_t indent_value = 4;
std::for_each ( m_data.begin(),
m_data.end(),
boost::bind( &print
, boost::bind( &Base::to_String
, _1
, indent_value )));
return 0;
}
It's still not quite what we what but we are getting closer. ;-)
Christian