#include <iostream> #include <vector> using namespace std; const vector<int>* fibon_seq( int size ) { const int max_size = 1024; /* 定义elems为fibon_seq()静态局部变量,与非 静态局部变量不同,静态局部变量在函数每次调用 中不会被释放或重新创建。与全局变量一样,数据 存放在全局数据区,但不同的是静态局部变量的作 用域是定义其的模块。 */ static vector< int > elems; //如果size大于max_size,则退出程序 if ( size <= 0 || size > max_size ){ cerr << "fibon_seq(): oops: invalid size: " << size << " -- can't fulfill request./n"; return -1; } // if size is equal to or greater than elems.size(), // no calculations are necessary ... for ( int ix = elems.size(); ix < size; ++ix ){ if ( ix == 0 || ix == 1 ) elems.push_back( 1 ); else elems.push_back( elems[ix-1]+elems[i