help
hi
i am a freshmen, i have a question about c++ stl.
first, i defined a struct PtrChannelExist and two functions:
SearchNodePtr isExistNodePtr
secondly, when I compile my project ver1.0 by VC6.0 in the
platform WindowXP.
the compiler indicated all is OK.
struct PtrChannelExist:
public binary_function<CChannel*,long,bool>{
bool operator()(const CChannel* lhs,const long rhs)const
{
return (lhs->m_lExternalChannelID) == rhs;
}
};
inline
channelPtrIt SearchNodePtr(ChannelPtrContainer& container,const long&
nodeID)
{
return
find_if(container.begin(),container.end(),bind2nd(PtrChannelExist(),nodeID));
}
inline
BOOL isExistNodePtr(const long& nodeID,ChannelPtrContainer& container)
{
BOOL isOk = false;
if (CheckNode(nodeID))
{
channelPtrIt it = SearchNodePtr(container,nodeID);
if ((it != container.end()) && (*it)->m_bChannelState)
isOk = true;
}
return isOk;
}
but , after i updated the struct PtrChannelExist and two
functions:
SearchNodePtr , the compiler indicated something were wrong.
template <typename OP>
class Xbinder2nd:
public unary_function<typename OP::first_argument_type,
typename OP::result_type>
{
protected:
OP _op;
typename OP::second_argument_type _n;
public:
Xbinder2nd(const OP& op,const typename OP::second_argument_type& n)
:_op(op),_n(n) {}
typename OP::result_type //return type
operator()(const typename OP::first_argument_type& x)const
{
return _op((*x)->m_lExternalChannelID,_n);
}
};
template<typename OP, typename T>
inline
Xbinder2nd<OP> Xbind2nd(const OP& op,const T& n)
{
typedef typename OP::second_argument_type OpSat;
return Xbinder2nd<OP>(op,(OpSat)n);
}
template<typename elementT,typename T>
inline
T::iterator SearchNodePtr(T container,elementT nodeID)
{
T::iterator findIt =
find_if(container.begin(),container.end(),bind2nd(equal<T::iterator,long>(),nodeID));
return findIt;
}
template<typename elementT,typename T>
inline
BOOL isExistNodePtr(elementT& nodeID,T& container)
{
return ((SearchNodePointer(container,nodeID) != container.end()) ?
true : false);
}
these are error message:
...\struct.h(266) : error C2780: 'bool __cdecl
std::equal(_II1,_II1,_II2,_Pr)' : expects 4 arguments - 0 provided
d:\program files\microsoft visual studio\vc98\include\xutility(33) :
see declaration of 'equal' comultiplayer\struct.h(274) : see
reference to function template instantiation 'class CChannel **__cdecl
SearchNodePointer(class std::vector<class CChannel *,class
std::allocator<class
CChannel *> >,long) ' being compiled
comultiplayer\struct.h(266) : error C2780: 'bool __cdecl
std::equal(_II1,_II1,_II2)' : expects 3 arguments - 0 provided
d:\program files\microsoft visual studio\vc98\include
\xutility(29) : see declaration of 'equal'
\comultiplayer\struct.h(274) : see reference to function
template instantiation 'class CChannel **__cdecl
SearchNodePointer(class std::vector<class CChannel *,class
std::allocator<class
CChannel *> >,long) ' being compiled