
Dwight Kelly ha escrito:
Hello,
I've encountered a problem compiling code that uses boost multi_index_container. I'm using both Microsoft Visual Studio 2005 and Apple's gcc 4.0.1. Visual Studio was very picky about how I used namespaces. I finally got it working with the code below.
The key to success was the 'using namespace boost::multi_index' line. If I attempted to prefix the members directly, eg.
typedef typename boost::multi_index::nth_index_const_iterator<0>::type left_const_iterator;
or
namespace mi=boost::multi_index; typedef typename mi::nth_index_const_iterator<0>::type left_const_iterator;
it would fail to compile.
However, when I attempt to compile the same code on Mac OS X using gcc 4.0.1 I get the following errors. Does anyone know why?
[...]
Hello Dwight,
For the sake of reference, let me reproduce the relevant part of your code:
using namespace boost::multi_index;
template
super; typedef typename super::template nth_index_const_iterator<0>::type left_const_iterator; typedef typename super::template nth_index_const_iterator<1>::type right_const_iterator;
As you see, you have to repeat the full type you are deriving from, which in the case of long multi_index_container instantiations is a bit annoying. Incidentally, you were missing some "template" keywords before nth_index_const_iterator, some compilers are lenient about this though. As for why your code compiled in VS, I'd say it was sheer luck: the code as you wrote it is illegal and VS should have complained. Looks like the using directive leads the compiler into taking the definitions of left_const_iterator and right_const_iterator as referring to the global variant of nth_index_const_iterator (which they are not) but on some further stage of the compilation the right variant ends up being chosen. Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo