I had this struct the other day:
struct foo_t {
char a, b, c;
} *foo = (foo_t*)untyped_memory;
…but having a named type for it was excessive. However, its unnamed form:
struct {
char a, b, c;
} *bar = untyped_memory;
...did not compile because of pointer types being incompatible.
Is there any way to make it work?
If you have access to C++11 or above then you can use decltype i.e.
struct {
char a, b, c;
} *bar = (decltype(bar))untyped_memory;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With