views:

24

answers:

2

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?

+1  A: 

You can try explicitly casting m_t to T*:

children
(
    #array
    (
        expr : ((($T1*)($c.m_elems.m_t))[$i],
        size : $c.m_elemCount
    )
)

I'm not near a dev machine now so there may be syntax errors here - but hopefully it gets the idea across.

Ofek Shilon
Hadn't seen the $T1 constant before, nice.
tenpn
+2  A: 

You've got a member variable called m_elems in your base class, and another member variable called m_elems in the derived class.

The $c.m_elems in $c.m_elems.m_t refers to the derived class's char array, not the base class's union.

Joe Gauterin
Ah! What a dupe I am. I changed the name in the child class and it works now. I didn't really want to edit this wtf-y code but there you go.
tenpn