一个变量可以在任何地方定义
但在定义之前是无法分配内存的
在变量定义前无法访问存储空间
//: C06:Nojump.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Can't jump past constructors
class X {
public:
X();
};
X::X() {}
void f(int i) {
if(i < 10) {
//! goto jump1; // Error: goto bypasses init
}
X x1; // Constructor called here
jump1:
switch(i) {
case 1 :
X x2; // Constructor called here
break;
//! case 2 : // Error: case bypasses init
X x3; // Constructor called here
break;
}
}
int main() {
f(9);
f(11);
}///:~
goto和switch都可能跳过构造函数调用的点
构造函数没有调用时,后面的程序块起作用
内存的分配是在堆栈中进行的。
内存分配通过向下移动堆栈指针实现的
无输出