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
      }
  }
};
                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++)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With