Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2-10-2 "block scope" for classes and namespaces
#1
Rule 2-10-2 is defined in terms of "block scopes" and "nested blocks". The only example is of a function and there is no mention of classes nor namespaces. Does "block" refer only to a compound statement as part of a function body, or is the intention to include other curly-brace-enclosed regions or scopes? For example, are any of the indicated lines violations of rule 2-10-2?

Code:
int i;
namespace n { int i; } // A
namespace { int i; } // B
class c { int i; }; // C

class c2 { int k; void f() { int k; } }; // D

class base { int z; };
class derived : public base { int z; }; // E
Reply
#2
2-10-2 is not purely about block scopes, so your examples A, B, C and D are violations of this rule, but E isn’t as a derived class is not an inner scope with respect to the base.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)