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.