C++ template programming question expected `;' before ‘it’?

c++, templates

Solution

You need to add `typename` before dependent types, i.e.

for(typename std::map<typename DecayerPolicy::indexpair, double >::const_iterator
    it = DecayerPolicy::mDecayRate.begin();
    it != DecayerPolicy::mDecayRate.end();
    it++)

Problem

I am writting a small piece of code exercising policy-based template programming. In this program, a CDecayer class is defined and it uses DecayerPolicy as its policy class. However the compiler complained that " expected `;' before ‘it’ " about the CDecayer part . Any suggestions? ``` #include <iostream> #include <vector> #include <map> #include <utility> int main() { } struct CAtom { }; class CStateUpdater { public: virtual void UpdateState(CAtom* patom) = 0; }; struct CDecayerPolicy { typedef std::pair<unsigned int, unsigned int> indexpair; std::map<indexpair, double> mDecayRate; CDecayerPolicy() { mDecayRate.clear(); } ~CDecayerPolicy() {} }; template<class DecayerPolicy> class CDecayer: public DecayerPolicy, public CStateUpdater { public: virtual void UpdateState(CAtom* patom) { for(std::map<DecayerPolicy::indexpair, double >::const_iterator it = DecayerPolicy::mDecayRate.begin(); it!= DecayerPolicy::mDecayRate.end(); it++) { // atom state modification code } } }; ```

Original source