gpt4 book ai didi

复杂继承中的 C++ 模板

转载 作者:行者123 更新时间:2023-11-28 07:47:22 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?

我有一个模板类型定义如下:

template<class TCoupon>
class CatBond : public Instrument {
public:
class arguments;
class engine;

//actual content
}

然后我想这样做:

template<class TCoupon>
class CatBond<TCoupon>::engine :
public GenericEngine<CatBond<TCoupon>::arguments,
CatBond<TCoupon>::results> {};

GenericEngine 在我尝试使用的 QuantLib 库中定义如下:

template<class ArgumentsType, class ResultsType>
class GenericEngine : public PricingEngine,
public Observer {
public:
PricingEngine::arguments* getArguments() const { return &arguments_; }
const PricingEngine::results* getResults() const { return &results_; }
void reset() { results_.reset(); }
void update() { notifyObservers(); }
protected:
mutable ArgumentsType arguments_;
mutable ResultsType results_;
};

但是,这不能编译:

Warning 1   warning C4346: 'Oasis::CatBond<TCoupon>::arguments' : dependent name is not a type  c:\users\ga1009\documents\dev\oasis\catbonds\CatBond.h  213
Error 2 error C2923: 'QuantLib::GenericEngine' : 'Oasis::CatBond<TCoupon>::arguments' is not a valid template type argument for parameter 'ArgumentsType' c:\users\ga1009\documents\dev\oasis\catbonds\CatBond.h 213

我怎样才能让它发挥作用?当 CatBond 是具体类型时,这种构造非常有效。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com