The following designated initializer example is valid in Visual Studio 2019 with /std:c++latest, but I'm wondering how to accomplish the same thing without designated initializers in Visual Studio 2017.
I am using C++ and I realize there is an object-oriented way to do this but I am NOT asking how to recreate this in C++ using constructors. This makes the tagging for this question a bit messy, sorry for any confusion.
I'm also struggling with the terminology here. Just to confirm, is &(struct Foo)
a compound literal? And this is achieving compile time static initialization? Could constexpr
be used somehow here instead?
// Header
struct Foo
{
void (*Bar)();
};
extern struct Foo *FooAPI;
// Source
static void Bar()
{
}
static struct Foo *FooAPI = &(struct Foo) { // Error: Expecting an expression
.Bar = Bar
};