A while ago, I was trying to implement my own v-tables (for educational purposes). To do that I used function pointers and lambdas. While doing so, I stumbled across an issue. Instead of posting the whole v-table code I just wrote a Minimal Reproducible Example.
For some reason, it doesn't compile (C2027 - use of undefined type Test):
class Test
{
int n;
static inline auto f = [](Test* t)
{
return t->n;
};
};
Even when I forward-declare Test like this: class Test;.
I am curious what causes this behavior because both int n and class Test are declared before the lambda.
I am using latest Visual Studio 2019 with C++17.
t->n;tries to use the class.