开发者

autoexp.dat not parsing union?

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)[$开发者_如何学Ci],
            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_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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜