開發平台(Platform): (Ex: Win10, Linux, ...)
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
http://tinyurl.com/y4hq4vfg
問題(Question):
submit
static int 無法初始化?
餵入的資料(Input):
static volatile int i = 0 ;
預期的正確結果(Expected Output):
Stdout:
init i
i1 = 0
i2 = 0
i1 = 1
i2 = 1
i1 = 2
錯誤結果(Wrong Output):i
Stdout:
runtime error: reference binding to null pointer of type 'struct value_type'
(stl_vector.h) - leet code spiral
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
void reverseString(vector<char>& s) {
static int i = 0 ;
static char *p = nullptr;
if( &s[0] != p )
{
p = &s[0];
i = 0;
cout << "init i " << endl;
}
cout << "i1 = " << i << endl;
if( i >= (s.size()/2) )
return;
cout << "i2 = " << i << endl;
swap( s[i] , s[s.size()-1-i]);
i++;
reverseString(s);
}
補充說明(Supplement):
我的i怎不會跑...