* Can not declare std::map::iterator in template (error: expected `;' before "my_A_iterator")
@ 2008-01-17 8:58 Erik
2008-01-17 9:20 ` William Gallafent
0 siblings, 1 reply; 2+ messages in thread
From: Erik @ 2008-01-17 8:58 UTC (permalink / raw)
To: gcc-help
I have the strange problem that I can not declare a std::map::iterator
inside a template:
#include <map>
template<typename S> struct A {};
template<typename T> struct B {
typedef A<T> G;
void f(G const & a) {
std::map<G const *, int> my_As;
std::map<G const *, int>::iterator my_A_iterator = my_As.find(&a);
}
};
The compiler says «error: expected `;' before "my_A_iterator"». If I
change A<T> to for example bool, it compiles. What could possibly be
wrong? I tried both g++-4.2.1 and g++-4.2.2.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Can not declare std::map::iterator in template (error: expected `;' before "my_A_iterator")
2008-01-17 8:58 Can not declare std::map::iterator in template (error: expected `;' before "my_A_iterator") Erik
@ 2008-01-17 9:20 ` William Gallafent
0 siblings, 0 replies; 2+ messages in thread
From: William Gallafent @ 2008-01-17 9:20 UTC (permalink / raw)
To: Erik; +Cc: gcc-help
On 16 Jan 2008, at 15:36, Erik wrote:
> I have the strange problem that I can not declare a std::map::iterator
> inside a template:
>
> #include <map>
> template<typename S> struct A {};
> template<typename T> struct B {
> typedef A<T> G;
> void f(G const & a) {
> std::map<G const *, int> my_As;
> std::map<G const *, int>::iterator my_A_iterator =
> my_As.find(&a);
> }
> };
>
>
> The compiler says «error: expected `;' before "my_A_iterator"». If I
> change A<T> to for example bool, it compiles. What could possibly be
> wrong? I tried both g++-4.2.1 and g++-4.2.2.
Not a GCC problem, but a problem with the code: add the word
"typename" to the beginning of that line to fix it.
See the language FAQ at http://www.parashift.com/c++-faq-lite/templates.html
for why ... question 35.18.
HTH,
--
Bill Gallafent.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-01-16 15:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-17 8:58 Can not declare std::map::iterator in template (error: expected `;' before "my_A_iterator") Erik
2008-01-17 9:20 ` William Gallafent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).