I have a struct which contains other structs as well as primative data types. I'd like to be able to access each member including members of the structs contained within the main struct with a template function.
For example:
struct B {
int y;
int z;
};
struct A {
int x;
B b;
};
template <typename TMember>
bool doSomething(A *a, TMember member) {
a->*member = 5; // some code accessing member
}
// Then access it with:
doSomething(&myA, &A::x);
// and likewise
doSomething(&myA, &A::b.y);
However the 2nd will not compile and throw a "object missing in reference to" error. I assume its because A does not have a member b.y?
Is there anyway to get the functionality that I want or will coding a different function be required?
(Note this is just an example and the code that I have contains a larger structure and will save me more time than just writing a second function.)
Thanks!