$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Stephen Torri (storri_at_[hidden])
Date: 2007-05-19 12:58:06
On Sat, 2007-05-19 at 11:12 -0500, Stephen Torri wrote:
> I get an error that 
> 
> Append_Frame.cpp: In member function 'virtual std::string libreverse::java_module::Append_Frame::to_String(uint32_t) const':
> Append_Frame.cpp:50: error: 'boost::bind' is not a class or namespace
> 
> Are you sure that the second argument is boost::bind::_1? I found that _1 is declared in boost/bind/placeholders.hpp as:
> 
> boost::arg<1> _1;
> 
> Stephen
Here is a test program that represents the problem we are trying to
solve. A vector contains boost shared pointers for a base class. For
each item in the container we want to call to_String with a value
representing the number of spaces to indent the output.
#include <string>
#include <sstream>
#include <boost/cstdint.hpp>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#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;
};
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(),
                    std::cout << boost::bind ( &Base::to_String,
                                               boost::bind::_1,
                                               indent_value ) );
    return 0;
}