我有这个模板类:
#include <utility>
#include <boost/locale.hpp>
#include <boost/range/iterator.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/algorithm_ext/insert.hpp>
#include <boost/icl/interval_set.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/list.hpp>
#include <boost/container/vector.hpp>
#include <boost/container/string.hpp>
#include <boost/foreach.hpp>
template<typename IntType>
class IntervalSet {
private:
boost::icl::interval_set<IntType> impl;
bool readonly;
bool doIchangeReadOnly() {
if(readonly){
// ERROR MESSAGE
}
return false;
}
public:
IntervalSet(const boost::icl::interval_set<IntType> &c) : impl(c), readonly(false) {}
IntervalSet(){}
static const IntervalSet EMPTY_SET;
static IntervalSet of(IntType a) {
IntervalSet r;
r.add(a);
return r;
}
// Create a set with all ints within range [a..b] (inclusive)
static IntervalSet of(IntType a, IntType b) {
IntervalSet r;
r.add(a, b);
return r;
}
// Add element el to the set.
void add(IntType el) {
if(doIchangeReadOnly()) return;
impl += el;
}
// Add interval; i.e., add all integers from a to b to set.
// If b<a, do nothing.
// Keep list in sorted order (by left range value).
// If overlap, combine ranges. For example,
// If this is {1..5, 10..20}, adding 6..7 yields
// {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}.
void add(IntType a, IntType b) {
if(doIchangeReadOnly() || b<a) return;
impl.add(boost::icl::interval<int>::type(a, b));
}
const boost::icl::interval_set<IntType>& data() const{
return impl;
}
void clear() {
if(doIchangeReadOnly()) return;
impl.clear();
}
// Remove element el from the set.
void remove(IntType el) {
if(doIchangeReadOnly()) return;
impl -= el;
}
// Add all elements from incoming set to this set.
// Return "this" so we can chain calls.
IntervalSet<IntType>& addAll(const IntervalSet<IntType> &set) {
if(doIchangeReadOnly()) return *this;
impl += set.impl;
return *this;
}
// Return the intersection of this set with the argument, creating a new set.
IntervalSet<IntType> and(IntervalSet<IntType> a) const {
a.impl &= impl;
return a;
}
};
template<typename IntType>
const IntervalSet<IntType> IntervalSet<IntType>::EMPTY_SET = IntervalSet<IntType<();
当我删除最后一个方法定义(IntervalSet<IntType>
和(IntervalSet<IntType> a) const
)时,g++ 只编译我的源代码。
我的问题:我到底做错了什么?
来自 g++ 的错误消息:
\m.cpp 137 error: expected ')' before 'a'
\m.cpp 137 error: 'a' does not name a type