M
muler
[C++ 98] 3.3.6.5 The potential scope of a declaration that extends to
or past the end of a class definition also extends to the regions
defined by its member definitions, even if the members are defined
lexically outside the class (this includes static data member
definitions, nested class definitions, member function definitions
(including the member function body and, for constructor functions
(12.1), the ctor-initializer (12.6.2)) and any portion of the
declarator part of such definitions which follows the identifier,
including a parameter-declaration-clause and any default arguments
(8.3.6).
// example:
int x = -1;
class Test {
public:
// according to the standard, global x is in scope of ctor-
initializer, so why is this an error?
Test() : x(-5) {}
};
I used visual studio C++ compiler (2010).
I never write such a weird looking code, but I want to understand what
the standard is saying.
Thanks,
or past the end of a class definition also extends to the regions
defined by its member definitions, even if the members are defined
lexically outside the class (this includes static data member
definitions, nested class definitions, member function definitions
(including the member function body and, for constructor functions
(12.1), the ctor-initializer (12.6.2)) and any portion of the
declarator part of such definitions which follows the identifier,
including a parameter-declaration-clause and any default arguments
(8.3.6).
// example:
int x = -1;
class Test {
public:
// according to the standard, global x is in scope of ctor-
initializer, so why is this an error?
Test() : x(-5) {}
};
I used visual studio C++ compiler (2010).
I never write such a weird looking code, but I want to understand what
the standard is saying.
Thanks,