Problem with template specification.

Dmitry V. Kustov kustov@nusun.jinr.ru
Sat Jul 7 05:11:00 GMT 2001


What is the problem in this code?

#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#define INPUTS 4
// æÕÎËÃÉÑ Ó×£ÒÔËÉ.
/********************************************************************/
template <int step> struct Reduce
{
  template <class InType, InType *input>
  static inline void Loop(double &summa, double *weight, double prevVAL)

  {
    double newVAL = *(input+step)*prevVAL;
    summa += *(++weight)*newVAL;
    Reduce<step-1>::Loop<InType,input>(summa,weight,newVAL);
    Reduce<step-1>::Loop<InType,input>(summa,weight,prevVAL);
  }
};
/*********************************************************************/
template <> struct Reduce<0>
{
  template <class InType, InType *input>
  static inline void Loop(double &summa, double *weight, double prevVAL)

  {
    summa += *(++weight)**input*prevVAL;
  }
};

float inputs[INPUTS];

main()
{
  double w[1<<INPUTS];
  for (int i=0;i<(1<<INPUTS);i++) w[i]=drand48();
  double summa = *w;
  Reduce<INPUTS-1>::Loop<float,inputs>(summa,w,1.0);
  cout << summa << endl;
}



More information about the Gcc-help mailing list