首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于template解决思路

2012-02-04 
关于template// TEMPLATE STRUCT unary_functiontemplateclass _A, class _Rstruct unary_function {typ

关于template
// TEMPLATE STRUCT unary_function
template<class _A, class _R>
struct unary_function {
typedef _A argument_type;
typedef _R result_type;
};
// TEMPLATE STRUCT binary_function
template<class _A1, class _A2, class _R>
struct binary_function {
typedef _A1 first_argument_type;
typedef _A2 second_argument_type;
typedef _R result_type;
};

template<class _Bfn>
class binary_negate
: public binary_function<_Bfn::first_argument_type, //@1
_Bfn::second_argument_type, bool> {
public:
explicit binary_negate(const _Bfn& _X)
: _Fn(_X) {}
bool operator()(const _Bfn::first_argument_type& _X,
const _Bfn::second_argument_type& _Y) const
{return (!_Fn(_X, _Y)); }
protected:
_Bfn _Fn;
};

@1: 此处为什么是_Bfn::second_argument_type而不是binary_function<_Bfn,....>::second_argument_type?

[解决办法]
...
[解决办法]
What is your point?
[解决办法]
从代码看,_Bfn应该是binary_function的一个实例类才可行,
binary_function<_Bfn,.... >::second_argument_type 是不可行的吧。

binary_function <_Bfn::first_argument_type, //@1 
_Bfn::second_argument_type, bool >
中binary_function需要的前两个模板参数直接使用_Bfn的两个参数类型。
[解决办法]
这时编译器帮你干的事。
[解决办法]
up

热点排行