我遇到了一些奇怪的错误,我需要一些帮助。这是代码:
观察.h:
class Obs;
struct Try : public std::pair<Item&, std::pair<int, int> > {
Item& item() const;
int dx() const;
int dy() const;
Try( Item& i, int _dx, int _dy );
};
struct Pred : public std::binary_function<Obs, Try, bool> {
bool operator() (Obs& o, Try& m) const;
};
class Obs {
Rect position;
public:
Obs (Rect dimensions);
bool Allows (Item i, int dx, int dy) const;
};
Obs.cpp:
Try::Try (Item& i, int _dx, int _dy) {
first = i;
second.first = _dx;
second.second = _dy;
}
bool Obs::Allows (Item i, int dx, int dy) const {
//
}
bool Pred::operator()(Obs& o, Try& m) const {
return !o.Allows( m.item(), m.dx(), m.dy() );
}
Item& Try::item() const {
return first;
}
int Try::dx() const {
return second.first;
}
int Try::dy() const {
return second.second;
}
ObsHolder.h:
class ObsHolder {
std::list< Obs* > list;
public:
void AddObstacle (Obs* obs);
bool CanMove (Item& i, int dx, int dy);
};
ObsHolder.cpp:
bool ObsHolder::CanMove (Item& i, int dx, int dy) {
return std::find_if( list.begin(), list.end(), std::bind2nd(Pred::operator(), Try(i, dx, dy) )) == list.end();
}
我得到的主要错误是:
'Pred::operator ()': 函数调用缺少参数列表;使用 '&Pred::operator ()' 创建指向成员的指针
我也得到:
c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(85): error C2440: 'initializing' : cannot convert from 'int' to 'Item &'
还有几下"*my_path*\microsoft visual studio 11.0\vc\include\utility(83)" complaining about std::pair