#include<iostream> using namespace std; class Test { public : Test(); }; Test::Test() { cout << " Constructor Called. " ; } void fun() { static Test t1; } int main() { cout << " Before fun() called. " ; fun(); fun(); cout << " After fun() called. " ; return 0; } |
(A) 我打电话来了。在fun()打电话之前。打完电话。 (B) 在fun()打电话之前。我打电话来了。我打电话来了。打完电话。 (C) 在fun()打电话之前。我打电话来了。打完电话。 (D) 我打电话来了。我打电话来了。打完电话。在fun()打电话之前。 答复: (C) 说明: 函数中的注意事项 fun()
,变量 t1
宣布 static
.因此 Test::Test
在程序的生命周期中,构造函数只被调用一次。 有关更多信息,请参阅 C++中的静态关键字 阅读“函数中的静态变量”一节 这个问题的小测验
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END