Я определил следующие шаблоны, используемые для объединения уже определенные предикаты:ошибка: ожидаемый неквалифицированный идентификатор до '||' Маркер
namespace SomeNamespace
{
//TODO: for now simply taking argument type of first predicate
template<typename LhPredicate, typename RhPredicate>
struct OrPredicate : public std::unary_function<typename LhPredicate::argument_type, bool>
{
public:
OrPredicate(LhPredicate const& lh, RhPredicate const& rh)
: m_lh(lh),
m_rh(rh)
{
}
bool operator()(typename LhPredicate::argument_type arg) const
{
return m_lh(arg) || m_rh(arg);
}
private:
LhPredicate m_lh;
RhPredicate m_rh;
};
//TODO: for now simply taking argument type of first predicate
template<typename LhPredicate, typename RhPredicate>
struct AndPredicate : public std::unary_function<typename LhPredicate::argument_type, bool>
{
public:
AndPredicate(LhPredicate const& lh, RhPredicate const& rh)
: m_lh(lh),
m_rh(rh)
{
}
bool operator()(typename LhPredicate::argument_type arg) const
{
return m_lh(arg) && m_rh(arg);
}
private:
LhPredicate m_lh;
RhPredicate m_rh;
};
template<typename LhPredicate, typename RhPredicate>
OrPredicate<LhPredicate, RhPredicate> or(LhPredicate const& lh, RhPredicate const& rh)
{
return OrPredicate<LhPredicate, RhPredicate>(lh, rh);
}
template<typename LhPredicate, typename RhPredicate>
AndPredicate<LhPredicate, RhPredicate> and(LhPredicate const& lh, RhPredicate const& rh)
{
return AndPredicate<LhPredicate, RhPredicate>(lh, rh);
}
}
Проблема при компиляции кода с использованием шаблонов вспомогательной функции (или/и), GCC жалуется на этих линиях:
AndPredicate<LhPredicate, RhPredicate> and(LhPredicate const& lh, RhPredicate const& rh)
OrPredicate<LhPredicate, RhPredicate> or(LhPredicate const& lh, RhPredicate const& rh)
так:
error: expected unqualified-id before '||' token
error: expected unqualified-id before '&&' token
Так что он действительно жалуется на те линии:
return m_lh(arg) && m_rh(arg);
return m_lh(arg) || m_rh(arg);
аргументы шаблона (предикаты должны быть объединены), конечно, правильно определить оператор() себя, и я действительно не знаю, что это проблема ССЗ - тот же код компилируется на VS2005 просто отлично.
Любая помощь будет высоко оценена.
'' and' и or' зарезервированные ключевые слова. Они являются синонимами для && и || операторы – Andrew