3

Why is this code not allowed?

int main()
{
    struct S
    {
        template<bool F>
        void f123()
        {
        }
    };
}

My compiler complains, that members of local classes are not allowed to be templates. What's the design decision behind that?

Yun
  • 3,056
  • 6
  • 9
  • 28
Bonita Montero
  • 2,817
  • 9
  • 22
  • 2
    Does this answer your question? [Member template in local class](https://stackoverflow.com/questions/4299314/member-template-in-local-class) – jjramsey Oct 06 '21 at 13:53
  • 3
    It's weird that this isn't allowed when `auto foo = [](auto test) { return test * test; };` is allowed and that create a closure object with a templated `operator()` – NathanOliver Oct 06 '21 at 13:58
  • 1
    This is a part of C++ since time immemorial. Used to be about linkage and templates. Then the linkage bit was relaxed and lambdas became generic to boot. This is just something no one revisited since. – StoryTeller - Unslander Monica Oct 06 '21 at 14:45

0 Answers0