At first some introductions: I am currently working on a C++ compatibility thing which means being able to run projects with different compiler options with each other. Therefore I test with a Release DLL and a Debug application linking to that other project. Most of the problems come up when using STL so I have to assure that both projects only use their own version of the STL. Thatswhy I have a wrapper class that can be build out of std::vectors, std::lists and so on but contains only an array which is completely compatible. Now I can wrap values in an array and unpack them on the other side into a valid STL object.
Now to get a bit closer to the question: There are some classes that contain STL but also need to be wrapped into an array. So I have to wrap the inner STL object, too, which means adding a tag and saving it right next to the associated array element.
Building up this wrapper class is no problem at all but unpacking it crashes with an access violation in the vector class right here:
const_reference operator[](size_type _Pos) const
{ // subscript nonmutable sequence
#if _HAS_ITERATOR_DEBUGGING
if (size() <= _Pos)
{
_DEBUG_ERROR("vector subscript out of range");
_SCL_SECURE_OUT_OF_RANGE;
}
#endif /* _HAS_ITERATOR_DEBUGGING */
_SCL_SECURE_VALIDATE_RANGE(_Pos < size());
return (*(_Myfirst + _Pos)); <---- HERE
}
The executing code at that moment is this:
template<class T>
struct mwContainerItem
{
T m_element;
void * m_tag;
};
template<class T>
class mwContainer
{
STLList ToList()
{
STLList l;
for(size_t i=0; i<m_size; ++i) <---- It crashes when accessing m_size
{
l.push_back(m_elements[i].m_element); <---- It also crashes when accessing m_elements
}
return l;
}
mwContainerItem<T>* m_elements;
size_t m_size;
};
The curious thing about it is I'm unpacking a std::list but it crashes in std::vector. Viewing at the whone thing I have a class contained by a std::vector and this very class contains a std::list of some basic class without STL. So unpacking means copying the outer array into a std::vector and every inner array into a std::list.
This error only occurs when I use the different compiler options, packing und unpacking in the very same project works just fine.
I really hope that anyone can help me cause I don't have any idea.
Regards