Template problem

From: Daniel Lidström (someone_at_microsoft.com)
Date: 01/19/04


Date: Mon, 19 Jan 2004 22:47:16 +0100

Hi,

is there anything wrong with this template function?
template<class T>
void print_percents(std::ostream& stream, int n, T vals)
{
  if( !vals.empty() ) {
    T::iterator it = vals.begin();
    stream << (*it).first << '/' << int(100*((*it).second / n)) << '%';
    for( ++ it; it!=vals.end(); ++ it )
      stream << ' ' << (*it).first << '/' << int(100*((*it).second / n)) <<
'%';
    stream << '\n';
  }
}

I can compile it with VC6 but gcc 2.95-3 gives this error:
.src/Hash.h: In function `void print_percents(ostream &, int, T)':
.src/Hash.h:68: parse error before `='
I.e. the line `T::iterator it = vals.begin();'
What's going on?
Thanks!

-- 
Daniel


Relevant Pages

  • Exporting classes with "templated" variables in a DLL
    ... It appears, whenever the class to be exported contains either a template function or template variable, the compiler complains. ... void sety(int num); ...
    (microsoft.public.vc.language)
  • Re: Exporting classes with "templated" variables in a DLL
    ... either a template function or template variable, ... void sety(int num); ... It's griping that you're exposing a member as a dll export that is of a type that is not itself a dll export. ...
    (microsoft.public.vc.language)
  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • [PATCH] get rid if __cpuinit and __cpuexit
    ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
    (Linux-Kernel)
  • [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes
    ... This adds basic support for KGDB on SuperH as well as adding some architecture ... -static int kgdb_uart_getchar ... -static void kgdb_uart_putchar ... * The command-line option can include a serial port specification ...
    (Linux-Kernel)