Template problem
From: Daniel Lidström (someone_at_microsoft.com)
Date: 01/19/04
- Next message: Jonathan Turkanis: "Re: Template problem"
- Previous message: Gunnar: "Re: int foo and int foo()"
- Next in thread: Jonathan Turkanis: "Re: Template problem"
- Reply: Jonathan Turkanis: "Re: Template problem"
- Reply: Daniel Lidström: "Re: Template problem"
- Reply: Martin Eisenberg: "Re: Template problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jonathan Turkanis: "Re: Template problem"
- Previous message: Gunnar: "Re: int foo and int foo()"
- Next in thread: Jonathan Turkanis: "Re: Template problem"
- Reply: Jonathan Turkanis: "Re: Template problem"
- Reply: Daniel Lidström: "Re: Template problem"
- Reply: Martin Eisenberg: "Re: Template problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|