Hello #cpp / #cplusplus Fediverse,
-
@oblomov Never mind:
#include <stdio.h>
struct par1 {
int par1a;
par1() : par1a(1) {}
};
struct par2 {
int par2a;
par2() : par2a(2) {}
};
struct child : par1, par2 {
int chfield3;
child() : chfield3(3) {}
};
int main () {
child ch;
printf("ch.par1a = %i, ch.par2a = %i, ch.chfield3 = %i\n",
ch.par1a, ch.par2a, ch.chfield3);
printf("&ch = %p, (par1 *)&ch = %p, (par2 *)&ch = %p\n",
&ch, (par1 *)&ch, (par2 *)&ch);
return 0;
}I might be able to make this work. Pondering.
-
sure: https://godbolt.org/z/YvYa9b7jb
You do lose the POD property on foo though. Depending on your needs this may or may not be important.
-
@ananas That's my fall-back approach, except it's not
reinterpret_cast<bar*>(foo), it'sfoo->gimme_bar(). Andfoo::gimme_bar()will beinline, and so will be the couple hundred procedures that takestruct foo *, so in the end, very little binary code will come out of it, only the source code will be awfully bulky. Not ideal.@ananas Well, if I have to autogenerate, I could do this instead:
template <class T>
void work_on_paydirt (T *ambi_object) {
struct bar *object = ambi_object->gimme_bar();
printf("Teh paydirt is %i\n", object->paydirt);
}Slightly less bulky, but it looks ugly.
-
sure: https://godbolt.org/z/YvYa9b7jb
You do lose the POD property on foo though. Depending on your needs this may or may not be important.
-
