Search code examples
c++classnestedfinal

Is a nested class of a final class automatically final?


I've a nested class in a final class. Is this nested class considered final by the C++ standard, or is it still possible to inherit from the inner class?

class A final
{
public:
   class B
      {
      ...
      };
   class C: public B;  // is this allowed (MSVC accepts it)?
   ...
};

class D: public A::B;  // is this allowed (MSVC accepts it)?

Visual studio accepts both. Why?


Solution

  • Visual studio accepts both. Why?

    Because it's legal. Nothing in the standard makes a nested class final just because its containing class is final.