I have an in-place vector class that’s defined like so:
template<class T>
class svectorbase
{
// ...
protected:
union
{
char* m_char;
T* m_t;
} m_elems;
size_t m_maxsize;
int m_elemCount;
};
template<class T, size_t maxsize>
class svector : public svectorbase<T>
{
protected:
char m_elems[sizeof(T) * maxsize]; // gets passed to base class
};
(Don’t ask why they didn’t just create a T m_array[maxsize]… sigh)
I’m trying to create an autoexp.dat entry for it in VS2005 because that structure makes it hard to look at in the debugger. I’ve got as far as:
svector<*>{
preview
(
#("size=",$e.m_elemCount,"/",$e.m_maxsize)
)
children
(
#array
(
expr : ($c.m_elems.m_t)[$i],
size : $c.m_elemCount
)
)
}
…but while the size attribute shows up correctly, the array is populated with (error):0 entries.
I’m probably doing something obvious to do with the union, but can’t see the forrest for the trees. Any ideas?
You’ve got a member variable called
m_elemsin your base class, and another member variable calledm_elemsin the derived class.The
$c.m_elemsin$c.m_elems.m_trefers to the derived class’schararray, not the base class’s union.