0

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

I have a template type defined as follows:

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

    //actual content
}

And then I want to do this:

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

where the GenericEngine is defined in the QuantLib library I am trying to work with as follows:

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_;
};

However, this doesn't compile:

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

how can I make it work? This construct worked nicely when CatBond was a concrete type.

Community
  • 1
  • 1
Grzenio
  • 35,875
  • 47
  • 158
  • 240
  • 2
    http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords – Pubby Jan 31 '13 at 16:28

1 Answers1

1

Following Pubby's hint, the correct implementation is:

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

the problem was that constructs like CatBond<TCoupon>::arguments are by default assumed to be a variable as opposed to a typename by the C++ compiler, so if in our case we need to explicitly state that these are types by using the typename keyword.

Grzenio
  • 35,875
  • 47
  • 158
  • 240