您的位置:程序门 -> c/c++ -> c++ 语言



bind3仿函数出了问题?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


bind3仿函数出了问题?
发表于:2007-09-20 18:05:17 楼主
#include <iostream>
#include <vector>
#include <algorithm>
using   namespace   std;

template   <class     _t,class   _res=bool   >
    struct         mybeetwen
    {         typedef     _res       restype;       typedef     _t       first_arg1;
          _res     operator   ()(const     _t   &x     ,const   _t&a,const   _t&b)       {     return       (x> =a)   &&   (x <=b)     ;}     };


template <class   operation,class   t>
    class   mybind3
    {
    typedef   typename   operation::restype     res;    
    typedef   typename   operation::first_arg1     arg1;    
    explicit     mybind3(const   operation   &   opx,const   t&   x,const   t&y):op(opx),a(x),b(y)   {}
          res       operator   ()(const     arg1&     data)     {return                 op(data,a,b);     }
    private:
        t       a,b;     operation     op;
    };


int   main()
{
vector <int>       v;
v.push_back(10);v.push_back(15);v.push_back(19);v.push_back(20);v.push_back(14);
        int   count=count_if(v.begin(),v.end(),   mybind3(mybeetwen(),10,20));
cout < <count;
}
error   c2955:   “mybeetwen”:   使用类   模板   需要   模板   参数列表
                e:\c++分支\aaaa\aaaa\ffffff.cpp(9)   :   参见“mybeetwen”的声明
e:\c++分支\aaaa\aaaa\ffffff.cpp(30)   :   error   c2955:   “mybind3”:   使用类   模板   需要   模板   参数列表
                e:\c++分支\aaaa\aaaa\ffffff.cpp(21)   :   参见“mybind3”的声明
生成日志保存在“file://e:\c++分支\aaaa\aaaa\debug\buildlog.htm”
发表于:2007-09-20 20:23:501楼 得分:0
#include <iostream>
#include <vector>
#include <algorithm>
using   namespace   std;

template   <class     _t,class   _res=bool>
    struct         mybeetwen
    {      
    typedef     _res       restype;       typedef     _t       first_arg1;
          _res     operator   ()(const     _t   &x     ,const   _t&a,const   _t&b)       {     return       (x> =a)   &&   (x <=b)     ;}  
    };


template <class   operation>
    class   mybinder3
    {
    typedef   typename   operation::restype     res;    
    typedef   typename   operation::first_arg1     arg;    
    explicit     mybinder3(const   operation   &   opx,const   arg&   x,const   arg&y):op(opx),a(x),b(y)   {}
          res           operator   ()(arg   data)     {return                 op <arg,res> (data,a,b);     }
    private:
        arg     a,b;     operation     op;
    };
template <class   operator,class   t1,class   t2>
inline     mybinder3 <operator>
                          mybind3   (const   operator     &   x,const   t1&   a,const   t2&   b)
                                                        {      
typedef   typename   operator::   first_arg1     arg;
return   mybinder3 <operator> (x,(arg)a,(arg)b   );
                                                        }


int   main()
{
vector <int>       v;
v.push_back(10);v.push_back(15);v.push_back(19);v.push_back(20);v.push_back(14);
        int   count=count_if(v.begin(),v.end(),   mybind3(mybeetwen(),10,20));
cout < <count;
}


  c2955:   “mybeetwen”:   使用类   模板   需要   模板   参数列表
                e:\c++分支\aaaa\aaaa\ffffff.cpp(11)   :   参见“mybeetwen”的声明
发表于:2007-09-20 20:41:352楼 得分:0
#include <iostream>
#include <vector>
#include <algorithm>
using   namespace   std;

template   <class   _t,class   _res=bool   >
struct   mybeetwen
{
typedef   _res   restype;
typedef   _t   first_arg1;
_res   operator   ()(const   _t   &x   ,const   _t&a,const   _t&b)  
{
return   (x> =a)   &&   (x <=b)   ;
}  
};


template <class   operation,class   t>
class   mybinder3
{
public:
typedef   typename   operation::restype   res;
typedef   typename   operation::first_arg1   arg1;
explicit   mybinder3(operation   opx,t     x,t   y):op(opx),a(x),b(y)   {}
res   operator   ()(const   arg1&   data)   {return   op(data,a,b);   }
private:
t   a,b;   operation   op;
};

template <class   operator,class   t>
inline   mybinder3 <operator,t>
mybind3   (operator   x,t   a,t   b)
{
return   mybinder3 <operator,t> (x,a,b   );
}


int   main()
{
vector <int>   v;
v.push_back(10);v.push_back(15);v.push_back(19);v.push_back(20);v.push_back(14);
int   count=count_if(   v.begin(),v.end(),   mybind3(   mybeetwen <int,bool> (),10,20)   );
cout < <count;
}
发表于:2007-09-20 20:53:383楼 得分:0
你的换行都到哪里去了   -   -

改了下


#include   <iostream>
#include   <vector>
#include   <algorithm>

using   namespace   std;

template   <class   _t,   class   _res   =   bool>
struct   mybeetwen
{      
        typedef   _res   restype;      
        typedef   _t     first_arg1;

        _res   operator   ()   (const     _t   &x     ,const   _t&a,const   _t&b)    
        {    
                return   (x> =a)   &&   (x <=b);
        }  
};


template <class   operation>
class   mybinder3
{
public   :
        typedef   typename   operation::restype     res;    
        typedef   typename   operation::first_arg1     arg;    
        explicit     mybinder3(const   operation   &   opx,const   arg&   x,const   arg&y):op(opx),a(x),b(y)   {}
        res   operator   ()(arg   data)  
        {
                return   op(data,a,b);  
        }
private:
        arg     a,b;    
        operation     op;
};

template <class   operator,class   t1,class   t2>
inline   mybinder3 <operator>   mybind3   (const   operator     &   x,const   t1&   a,const   t2&   b)
{      
        typedef   typename   operator::first_arg1     arg;
        return   mybinder3 <operator> (x,(arg)a,(arg)b   );
}


int   main()
{
        vector <int>   v;
        v.push_back(10);
        v.push_back(15);
        v.push_back(19);
        v.push_back(20);
        v.push_back(14);
        size_t   count   =   count_if(v.begin(),   v.end(),   mybind3(mybeetwen <int> (),   10,   20));
        cout < <count;

        return   0;
}


发表于:2007-09-20 23:48:374楼 得分:0
#include <iostream>
#include <vector>
#include <algorithm>
using   namespace   std;

template   <class     _t,class   _res=bool   >
    struct         mybeetwen
    {         typedef     _res       restype;       typedef     _t       first_arg1;
          _res     operator   ()(const     _t   &x     ,const   _t&a,const   _t&b)       {     return       (x> =a)   &&   (x <=b)     ;}     };


template <class   operation,class   t>
    class   mybind3
    {
public:
    typedef   typename   operation::restype     res;    
    typedef   typename   operation::first_arg1     arg1;    
    explicit     mybind3(const   operation   &   opx,const   t&   x,const   t&y):op(opx),a(x),b(y)   {}
          res       operator   ()(const     arg1&     data)     {return                 op(data,a,b);     }
    private:
        t       a,b;     operation     op;
    };


void   main()
{
vector <int>       v;
v.push_back(10);v.push_back(15);v.push_back(19);v.push_back(20);v.push_back(14);
        int   count=count_if(v.begin(),v.end(),   mybind3 <mybeetwen <int> ,int> (mybeetwen <int> (),10,20));
cout < <count;
}


快速检索

最新资讯
热门点击