g++ 3.4.3 template error

David Brumley djbrums@gmail.com
Fri Sep 2 17:58:00 GMT 2005


Hello,
I'm having a problem with template functions in some legacy code i'm
trying to get working. I can reproduce the error in the following
small example:

include <map>
#include <iterator>
using namespace std;
class foo {
  public:
    foo(){};
    template<class T> void setval(){
        map<T,int> mymap;
        map<T,int>::iterator it;
    }
};

The decl of mymap succeeds, or at least there is no compile-time
error.  The iterator it decl fails with the error
error: expected `;' before "it"

I nor anyone else around me have been able to figure out a way to get
the iterator decl of a template function to work.  Is this a bug, or
something I am not doing right? From what I understand this code
compiled fine under old versions of g++.

Or is there a workaround? Essentially I need to make it so the
iterator over a map is a template type.

Thanks,
david



More information about the Gcc-help mailing list