0

I am getting error: expected unqualified-id before 'typename' in line 59 when I try to compile this:

#include <cstdlib>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>


template <typename ValueT, typename SizeT = size_t>
struct Test {
    typedef SizeT SizeType;
    typedef ValueT ValueType;
    struct ValueTag {};
    struct ProbabilityTag {};
    struct TotalProbabilityTag {};
    struct NodeType {
        SizeType value;
        ValueType probability;
        ValueType totalProbability;

        typedef boost::multi_index_container<
            NodeType,
            boost::multi_index::indexed_by<
                boost::multi_index::ordered_unique<
                    boost::multi_index::tag<ValueTag>,
                    BOOST_MULTI_INDEX_MEMBER(NodeType, SizeType, value)
                >,
                boost::multi_index::ordered_non_unique<
                    boost::multi_index::tag<ProbabilityTag>,
                    BOOST_MULTI_INDEX_MEMBER(NodeType, ValueType, probability)
                >,
                boost::multi_index::ordered_non_unique<
                    boost::multi_index::tag<TotalProbabilityTag>,
                    BOOST_MULTI_INDEX_MEMBER(NodeType, ValueType, totalProbability)
                >
            > 
        > NodeIndexType;

        NodeIndexType * node;
        NodeType(const NodeType & o):
            value(o.value),
            probability(o.probability),
            totalProbability(o.totalProbability)
        {
            if (o.node != NULL) {
                this->node = new NodeIndexType(*(o.node));
            }
        }

        ~NodeType() {
            delete this->node;
        }

        bool operator< (const NodeType & b) const {
            return this->value < b.value;
        }
    };

    typedef typename NodeType::NodeIndexType NodeIndexType;
    typedef NodeIndexType::typename index<typename ValueTag>::type ViewNodeByValue; /* this does not work */
};


int main() {
    Test<int> a;

    return EXIT_SUCCESS;
}

It all works fine if I remove the commented line. I have already seen template parameter to boost multi index container but I cannot find a way to get this working within a templated structure or class.

Anyone who can tell me how to fix this?

See http://codepad.org/UPMapaXI for the error message.

Community
  • 1
  • 1
user2525536
  • 366
  • 1
  • 4
  • 14

1 Answers1

1

Running some more tests and looking at the related question again made it obvious that the correct way of doing this is

typedef typename NodeIndexType::template index<ValueTag>::type NodeByValue;

as already explained in template parameter to boost multi index container. The important point was to mark index as template.

An alternative is to use

typedef typename boost::multi_index::index<NodeIndexType, ValueTag>::type ViewNodeByValue;

which I found in boost multi index container of template-dependent struct in template-class.

Community
  • 1
  • 1
user2525536
  • 366
  • 1
  • 4
  • 14
  • I had same issue and gcc 4.8.5 was giving me the suggestion: CollectionManager.hpp:50:32: note: use CollectionManager::CollectionContainer::template index to indicate that it is a template – sfanjoy Nov 04 '17 at 16:00