-1

我正在编写以下代码:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  struct test1
  {
    struct test2
    {
      struct test3
      {
        enum TokenType
        {
          COMMA_TOKEN, EOF_TOKEN,
        } token_value;
      } b;
    } c;
  };

  struct test2 hsd;
  hsd.b.token_value = 2;

  return 0;
}

strut test2、test3和enum的范围应该在struct test1内吗?但是编译器没有报错,顺便编译了MinGW GCC。

4

1 回答 1

1

In C such code is allowed, since all types are declared in a single namespace.

In C++ compiler should produce an error, since struct test2 in declared in scope of struct test1. In C++ your variable should be declared as follows:

    test1::test2 hsd;
于 2013-07-01T14:10:44.360 回答