Boost logo

Boost :

From: Steven Kirk (steven.kirk_at_[hidden])
Date: 2001-03-16 09:31:44


Am I doing something wrong here? I'm trying to create a projection iterator
that returns a reference to the object pointed to by a map's mapped_type:

--
#include <boost/iterator_adaptors.hpp>
#include <map>
class Abstract {
public:
    virtual void example() = 0;
    int data;
};
typedef std::map<int, Abstract*> AbstractMap;
struct GetReference {
    typedef Abstract result_type;
    typedef AbstractMap::value_type argument_type;
    Abstract &operator()(argument_type &a) const { return *a.second; }
};
int main(int argc, char* argv[])
{
    AbstractMap v;
    boost::projection_iterator_generator<GetReference,
    AbstractMap::iterator>::type i;
    return 0;
}
--
The problem arises because the reference I'm returning is an abstract type.
I get the following errors on Borland C++ (and get similar ones on GCC):
--
[C++ Error] conversion_traits.hpp(108): E2352 Cannot create instance of
abstract class 'Abstract'
[C++ Error] conversion_traits.hpp(108): E2353 Class 'Abstract' is abstract
because of 'Abstract::example() = 0'
[C++ Error] ITERATOR_ADAPTORS.HPP(672): E2352 Cannot create instance of
abstract class 'Abstract'
[C++ Error] ITERATOR_ADAPTORS.HPP(672): E2353 Class 'Abstract' is abstract
because of 'Abstract::example() = 0'
[C++ Error] Unit1.cpp(23): E2450 Undefined structure
'boost::iterator_adaptor<__rwstd::__rb_tree<int,std::pair<const int,Abstract
*>,__rwstd::__select1st<std::pair<const int,Abstract
*>,int>,std::less<int>,std::allocator<std::pair<const int,Abstract *> >
>::iterator,boost::projection_iterator_policies<GetReference>,Abstract,boost
::detail::default_argument,boost::detail::default_argument,boost::detail::de
fault_argument,boost::detail::default_argument>'
[C++ Error] Unit1.cpp(23): E2449 Size of 'i' is unknown or zero
[C++ Error] Unit1.cpp(23): E2450 Undefined structure
'boost::iterator_adaptor<__rwstd::__rb_tree<int,std::pair<const int,Abstract
*>,__rwstd::__select1st<std::pair<const int,Abstract
*>,int>,std::less<int>,std::allocator<std::pair<const int,Abstract *> >
>::iterator,boost::projection_iterator_policies<GetReference>,Abstract,boost
::detail::default_argument,boost::detail::default_argument,boost::detail::de
fault_argument,boost::detail::default_argument>'
--
Can anyone help?

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk