这是我的代码:
using namespace std;
class Pixel
{
public:
bool AreSamplesIdentical() const
{
return true;
}
};
namespace
{
class Predicate_SamplesEqual : public unary_function<const Pixel&, bool>
{
public:
bool operator () (const Pixel& pixel) const
{
return pixel.AreSamplesIdentical();
}
};
}
int main()
{
vector<Pixel> pixels(10);
find_if(pixels.begin(), pixels.end(), not1(Predicate_SamplesEqual()));
}
在 Visual Studio 2008 C++ Express 上,我收到错误:错误 C2529:'_Left':对引用的引用是非法的来自库代码内部。
但我在这里试过,它编译:http: //ideone.com/swWrZT
这里谁错了?如果是我,我该如何编写解决方法?
错误发生在功能指示的行上
// TEMPLATE CLASS unary_negate
template<class _Fn1>
class unary_negate
: public unary_function<typename _Fn1::argument_type, bool>
{ // functor adapter !_Func(left)
public:
explicit unary_negate(const _Fn1& _Func)
: _Functor(_Func)
{ // construct from functor
}
/**error**/bool operator()(const typename _Fn1::argument_type& _Left) const
{ // apply functor to operand
return (!_Functor(_Left));
}
protected:
_Fn1 _Functor; // the functor to apply
};