In my code there is the following typedef:
typedef unsigned long int ulint;
typedef std::map<ulint, particle> mapType;
typedef std::vector< std::vector<mapType> > mapGridType;
particle - This is a custom class without a 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 ) {
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;
}
objectMapis an object mapGridType. The error is being read:
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 am wrong, but the code above should not ring at all map::operator[]. The first call operator[]is performed in vector< vector<mapType> >and returns a vector<mapType>, the second is in vector<mapType>and returns a mapTypeaka a map<ulint, particle>, and I call only begin()and endon this map. So why am I getting an error trying to compile operator[]for map?
source
share