相关疑难解决方法(0)

为什么类中的方法顺序不适用于C++?

我已经用C++编程了很长一段时间,直到今天我才想到这一点.

请考虑以下代码:

struct foo
{
  // compiles fine
  void bar()
  {
    a = 1;
    my_int_type b;
    b = 5;
  }

  // Just a declaration, this fails to compile, which leads me to assume that
  // even though the bar() method is declared and defined all at once, the
  // compiler looks/checks-syntax-of the class interface first, and then compiles
  // the respective definitions...?
  void bar2(my_int_type); // COMPILE ERROR

  my_int_type       b; // COMPILE ERROR because it comes before the typedef declaration
  typedef …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction

3
推荐指数
2
解决办法
309
查看次数

标签 统计

c++ ×1

compiler-construction ×1