Q:

Pointer-to-data-member-of-data-member

I had the following piece of code (simplified for this question):
struct StyleInfo
{
    int width;
    int height;
};

typedef int (StyleInfo::*StyleInfoMember);

void AddStyleInfoMembers(std::vector<StyleInfoMember>& members)
{
    members.push_back(&StyleInfo::width);
    members.push_back(&StyleInfo::height);
}

Now, we had to restructure this a bit, and we did something like this:
struct Rectangle
{
    int width;
    int height;
};

struct StyleInfo
{
    Rectangle size;
};

typedef int (StyleInfo::*StyleInfoMember);

void AddStyleInfoMembers(std::vector<StyleInfoMember>& members)
{
    members.push_back(&StyleInfo::size::width);
    members.push_back(&StyleInfo::size::height);
}

If this all looks like a stupid thing to do, or if you feel there's a good opportunity to apply BOOST here for some reason, I must warn you that I really simplified it all down to the problem at hand:

error C3083: 'size': the symbol to the left of a '::' must be a type

The point I'm trying to make is that I don't know what the correct syntax is to use here. It might be that "StyleInfo" is not the correct type of take the address from to begin with, but in my project I can fix that sort of thing (there's a whole framework there). I simply don't know how to point to this member-within-a-member.

A:

Remember a pointer to a member is just used like a member.
 Obj x;

 int  y = (x.*)ptrMem;

But like normal members you can not access members of subclasses using the member access mechanism. So what you need to do is access it like you would access a member of the object (in your case via the size member).
#include <vector>
#include <iostream>

struct Rectangle
{
    int width;
    int height;
};

struct StyleInfo
{
    Rectangle size;
};

typedef Rectangle   (StyleInfo::*StyleInfoMember);
typedef int         (Rectangle::*RectangleMember);

typedef std::pair<StyleInfoMember,RectangleMember>  Access;

void AddStyleInfoMembers(std::vector<Access>& members)
{
    members.push_back(std::make_pair(&StyleInfo::size,&Rectangle::width));
    members.push_back(std::make_pair(&StyleInfo::size,&Rectangle::height));
}

int main()
{
    std::vector<Access>     data;
    AddStyleInfoMembers(data);

    StyleInfo       obj;
    obj.size.width  = 10;

    std::cout << obj.*(data[0].first).*(data[0].second) << std::endl;
}

This is not something I would recommend doing!
An alternative (that I recommend even less) is to find the byte offset from the beginning of the class and then just add this to the objects address. Obviously this will involve a lot of casting backwards and forwards so this looks even worse then the above.

