亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將一個無效參數傳遞給了將無效參數視為嚴重錯誤的函數!

將一個無效參數傳遞給了將無效參數視為嚴重錯誤的函數!

C++
狐的傳說 2023-04-22 17:13:39
源代碼:#include<iostream>#include<vector>#include<algorithm>#include<iterator>using namespace std;//function solveint*solve(int n, int m){vector<int>a;vector<int>b;vector<int>c;int ptrOFc = 0;for (int i = 0; i < n+1; i++){a.push_back(i);}while (m < n){int t = n--;c[ptrOFc++] = a[m];a.erase(remove(a.begin(), a.end(), a[m]));for (int i = 1; i < n - m + 1; i++)b = a[m++];for (int i = 1; i < m; i++)b.push_back(a);a = b;}copy(c.begin(), c.end(), ostream_iterator<int>(cout," "));return &c[0];}int main(){solve(10, 2);return 0;}編譯器報錯:0x5ED4A893 (msvcr120d.dll) (ConsoleApplication1.exe 中)處有未經處理的異常: 將一個無效參數傳遞給了將無效參數視為嚴重錯誤的函數。PS:請高手看一下,是我使用vector容器的方法有誤,還是VS軟件的問題
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

vector<int>c;是在函數里定義的,作用域就只在這個函數里,而你將&c[0]返回是有問題的

查看完整回答
反對 回復 2023-04-25
  • 1 回答
  • 0 關注
  • 1050 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號