template mem fun problem gcc-3.0.2

Neal D. Becker nbecker@fred.net
Fri Feb 1 07:35:00 GMT 2002


This code gives a syntax error.  I think it should not.
g++3 -v -c TestIIR.cc 
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.0.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux
Thread model: posix
gcc version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3)
 /usr/lib/gcc-lib/i386-redhat-linux/3.0.2/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=2 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ TestIIR.cc -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase TestIIR.cc -version -o /tmp/ccVFPFWa.s
GNU CPP version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3) (i386-redhat-linux)
	compiled by GNU C version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3).
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++-v3
 /usr/include/g++-v3/i386-redhat-linux
 /usr/include/g++-v3/backward
 /usr/local/include
 /usr/lib/gcc-lib/i386-redhat-linux/3.0.2/include
 /usr/include
End of search list.
TestIIR.cc: In function `int main()':
TestIIR.cc:6: parse error before `.' token

#ifndef _IIR_H
#define _IIR_H

// $Id: IIR.H,v 1.1 1999/11/24 14:23:26 nbecker Exp $

#include <algorithm>
#include <vector>
#include <complex>
#include <cmath>

using std::vector;
using std::complex;

template<class coeftype, class inputtype = coeftype>
class IIR {
  vector<coeftype> num;
  vector<coeftype> den;
  int order;
  vector<inputtype> z;
public:
  // h(z) = (a0 + a1 z^-1 + ...)/(1 + b1 z^-1 + ...)
  template<class NumInputIterator, class DenInputIterator>
  IIR (NumInputIterator numstart, NumInputIterator numend, DenInputIterator denstart, DenInputIterator denend) :
    num (numstart, numend),
    den (denstart, denend),
    order (std::max (num.size(), den.size())),
    z (order)
    {}

  // initialize internal state
  template<class NumInputIterator, class DenInputIterator, class CoefIterator>
  IIR (NumInputIterator numstart, NumInputIterator numend, DenInputIterator denstart, DenInputIterator denend, CoefIterator zstart, CoefIterator zend) :
    num (numstart, numend),
    den (denstart, denend),
    order (std::max (num.size(), den.size())),
    z (zstart, zend)
    {}

  // Noop default
  IIR () {}

  template <class outputtype>
  outputtype Compute (inputtype x) {
    inputtype w = x;
    for (int i = 1; i < den.size(); i++)
      w += -den[i] * z[i];

    outputtype y = num[0] * w;
    for (int i = 1; i < num.size(); i++)
      y += num[i] * z[i];

    for (int i = order - 1; i > 1; i--)
      z[i] = z[i-1];

    z[1] = w;

    return y;
  }

  template <class outputtype>
  void Compute (inputtype x, outputtype &out) {
    out = Compute<outputtype> (x);
  }

  void Reset (inputtype x = 0) {
    for (int i = 0; i < z.size(); i++)
      z[i] = x;
  }

  template<typename flt>
  complex<flt> H (complex<flt> z) const {
    complex<flt> zi = pow (z, -1);
    complex<flt> top (0., 0);
    for (int i = 0; i < num.size(); i++)
      top += num[i] * pow (zi, i);

    complex<flt> bot (1.,0);
    for (int i = 1; i < den.size(); i++)
      bot += den[i] * pow (zi, i);

    return top/bot;
  }

  template<typename flt>
  flt MagSqr (complex<flt> z) const {
    return norm (H (z));
  }

};


#endif
#include "IIR.H"

int main () {
  IIR<double> iir;
  double x;
  double y iir.Compute<double> (x);
}



More information about the Gcc-bugs mailing list