B
BigBrian
I'm working a legecy system and have been tasked with upgrading the
compiler from gcc 2.95.2 to 3.4.2. I have the following class which
contains several std::map's. For simplicity, here I've created two a
map from int to int and int to double. The keys are "schronized", ie
all items are added in the set of maps by way of the add() member
function. There is a template function that basically handles the
error of the items not being in the map when remove is called. This
code compiles with 2.95.2 but does not with 3.4.2....
Here's a representation of the real code..
#include <iostream>
#include <map>
class A
{
private:
std::map<int,int> int_map;
std::map<int,double> double_map;
template< class T >
void helper( std::map<int,T> & t, int value );
public:
void add( int key, int int_value, double double_value )
{
int_map[key] = int_value;
double_map[key] = double_value;
}
void remove( int key )
{
helper( int_map, key);
helper( double_map, key );
}
};
template< class T >
void A::helper( std::map<int,T> & t,int value )
{
std::map<int,T>::iterator i = t.find( value );
if ( i == t.end() )
{
std::cerr << "not found" << std::endl;
}
else
{
t.erase(i);
}
}
int main()
{
A a;
a.add( 1, 2, 5.4 );
a.remove( 1 );
return 0;
}
I get the following compiler error:
error: expected ';' before "i"
error: 'i' undeclared (first use this function)
.....
......
The errors go on to say...
error: dependent-name 'std::map<int,T>::iterator' is parsed as a
non-type but instanciation yields a type.
Thus I've tried putting "typename std::map<int,T>::iterator" on the
line before i is instanciated, but that doesn't help.
I realize that it's probably not the best design to have multiple maps
to store information like this, but I can't change this now.
Any information will be appreciated.
compiler from gcc 2.95.2 to 3.4.2. I have the following class which
contains several std::map's. For simplicity, here I've created two a
map from int to int and int to double. The keys are "schronized", ie
all items are added in the set of maps by way of the add() member
function. There is a template function that basically handles the
error of the items not being in the map when remove is called. This
code compiles with 2.95.2 but does not with 3.4.2....
Here's a representation of the real code..
#include <iostream>
#include <map>
class A
{
private:
std::map<int,int> int_map;
std::map<int,double> double_map;
template< class T >
void helper( std::map<int,T> & t, int value );
public:
void add( int key, int int_value, double double_value )
{
int_map[key] = int_value;
double_map[key] = double_value;
}
void remove( int key )
{
helper( int_map, key);
helper( double_map, key );
}
};
template< class T >
void A::helper( std::map<int,T> & t,int value )
{
std::map<int,T>::iterator i = t.find( value );
if ( i == t.end() )
{
std::cerr << "not found" << std::endl;
}
else
{
t.erase(i);
}
}
int main()
{
A a;
a.add( 1, 2, 5.4 );
a.remove( 1 );
return 0;
}
I get the following compiler error:
error: expected ';' before "i"
error: 'i' undeclared (first use this function)
.....
......
The errors go on to say...
error: dependent-name 'std::map<int,T>::iterator' is parsed as a
non-type but instanciation yields a type.
Thus I've tried putting "typename std::map<int,T>::iterator" on the
line before i is instanciated, but that doesn't help.
I realize that it's probably not the best design to have multiple maps
to store information like this, but I can't change this now.
Any information will be appreciated.