class FunctionBase {
public:
const double operator() (double a_) const = 0;
}
class AddN : public FunctionBase {
public:
AddN (int n_) : FunctionBase(), _n(n_) {}
const double operator() (double a_) const { return (a_ + n); }
private:
int _n;
}
FunctionBase *コンパイラが aAddNから aを再構築できないため、プレースホルダーとして使用する必要がありますかFunctionBase、または使用する方法はありますFunctionBase &か?
- 編集 -
私は を持っていstd::map<std::string, FunctionBase *>ますが、ポインターの代わりに参照を使用できるかどうかに興味があるので、使用する前にポインターが NULL ではないことを保証できます。コードのエラー耐性を高めようとしています。に切り替えるとFunctionBase &、コンパイラはインスタンス化できないと不平を言いますAddNが、FunctionBase &これは完全に理にかなっていますが、私が知らなかった一般的な回避策があることを望んでいました.