I have the following typedef's in my code:
typedef unsigned long int ulint;
typedef std::map<ulint, particle> mapType;
typedef std::vector< std::vector<mapType> > mapGridType;
particle
is a custom class with no default constructor.
VS2008 gives me an error in this code:
std::set<ulint> gridOM::ids(int filter)
{
std::set<ulint> result;
ulint curId;
for ( int i = 0; i < _dimx; ++i ) {
for ( int j = 0; j < _dimy; ++j ) {
// next line is reported to be erroneous
for ( mapType::iterator cur = objectMap[i][j].begin(); cur != objectMap[i][j].end(); ++cur )
{
curId = (*cur).first;
if ( (isStatic(curId) && filter != 2) || (!isStatic(curId) && filter != 1) )
{
result.insert(curId);
}
}
}
}
return result;
}
objectMap
is an object of mapGridType
. The error reads:
error C2512: 'gridOM::particle::particle' : no appropriate default constructor available
while compiling class template member function 'gridOM::particle &std::map<_Kty,_Ty>::operator [](const unsigned long &)'
with
[
_Kty=ulint,
_Ty=gridOM::particle
]
.\gridOM.cpp(114) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
with
[
_Kty=ulint,
_Ty=gridOM::particle
]
Correct me if I'm wrong, but the above code should not be making calls to map::operator[]
at all. The first operator[]
call is made to vector< vector<mapType> >
and returns a vector<mapType>
, the second is made to vector<mapType>
and returns a mapType
aka a map<ulint, particle>
, and I only call begin()
and end
on that map. So why do I get an error trying to compile the operator[]
for map
?