Are pointers to pure virtual member functions of local classes allowed?
06:22 31 Oct 2025
Consider the following snippet:
int main() {
struct Local {
virtual void foo() = 0;
};
void (Local::* ptr)() = &Local::foo;
}
When compiling with C++20, GCC 13.3.0 and Clang 18.1.3 both compile this code, but MSVC 19.39 thru 19.43 generate the following compiler error:
(3): error C3640: 'main::Local::[thunk]: __cdecl `int __cdecl main(void)'::`2'::Local::`vcall'{0,{flat}}' }'': a referenced or virtual member function of a local class must be defined
I could not find anything in the C++20 standard to prove either compiler right. Is the code snippet well-formed?
We use cookies to ensure the best experience on our website. This includes analytics, personalization, and marketing purposes. Some cookies are essential for the website to function properly.
By clicking "Accept", you consent to our use of cookies. You can read more about how we use cookies and how you can change your preferences in our Privacy Policy.