小编Ami*_*avi的帖子

4
推荐指数
1
解决办法
1707
查看次数

如何使函数的返回类型与另一个函数相同?

我们的研究书中有一个关于对象函数的问题.在c ++中有一个代码,问题是我们要填补空白.代码如下

template <typename Arg, typename Ret> 
class FuncObj {
public:
    typedef Arg argType;
    typedef Ret retType;
    virtual Ret operator()(Arg) = 0;
};

class DivideBy : public FuncObj<int, double> {
protected:
    int divisor;
public:
    DivideBy(int d) {
        this->divisor = d;
    }
    double operator()(int x) {
        return x/((double)divisor);
    }
};

class Truncate : public FuncObj<double, int> {
public:
    int operator()(double x) {
        return (int) x;
    }
};

template < typename Ftype , typename Gtype >
class Compose : public FuncObj <typename …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance c++11

0
推荐指数
1
解决办法
116
查看次数