【发布时间】:2015-07-12 17:45:17
【问题描述】:
当我尝试编译此代码时,我在第 59 行收到 error: expected unqualified-id before 'typename':
#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;
}
如果我删除注释行,一切正常。我已经看过template parameter to boost multi index container,但我找不到在模板结构或类中让它工作的方法。
谁能告诉我如何解决这个问题?
有关错误消息,请参阅http://codepad.org/UPMapaXI。
【问题讨论】:
标签: templates boost-multi-index