如題
演算法想要用函式來取得多維矩陣的初始解
可是我發現會卡在一個BUG 爬文也看不懂
開一個矩陣ini[2][2]
以下是我的程式碼
我只希望在main裡面可以呼叫test()然後把矩陣裡面的值給存取出來
#include "stdafx.h"
#include "stdlib.h"
#include "iostream"
using namespace std;
void test(int* ini)
{
ini[0][0]=1;
ini[0][1]=2;
ini[1][0]=1;
ini[1][1]=2;
}
int _tmain(int argc, _TCHAR* argv[])
{
int ini[2][2]={0};
test (&ini[0][0]);
cout<<ini[0][0]<<endl<<ini[0][1];
system("pause");
return 0;
}
可是執行出現了一句話
"註標必須使用在陣列或指標型別上"
想請問一下各位高手們我這段程式是哪邊錯了
void test(int** ini)test (ini);
作者:
purpose (秀才遇到肥宅兵)
2014-04-26 14:34:00置底文有寫
作者:
EdisonX (卡卡獸)
2014-04-26 16:11:00void test( int (*ini)[2] ) ; ????
作者:
LPH66 (-6.2598534e+18f)
2014-04-26 17:57:00void test( int ini[][2] ) ; 比較標準的寫法是這樣
作者:
descent (「雄辯是銀,沉默是金」)
2014-04-26 18:01:00你用了 c++, 要不要考慮用 std::vector
作者:
Feis (永遠睡不著 @@)
2014-04-26 20:03:00void test(int (&in)[2][2]); 為什麼不這樣?
作者:
q82419 (q82419)
2014-04-26 20:39:00包成struct傳我個人是習慣包成struct 如果要傳2維以上的如果你是用純C的話啦 C++的話就如上vector
作者:
EdisonX (卡卡獸)
2014-04-26 22:16:00看到 header, 你還是用 C++ vector 吧 , 不要為了這小問題卡那麼久,沒必要,你還要接下來的事要做..
作者:
q82419 (q82419)
2014-04-26 22:25:00header?? 那不是VS幫你掛上的東西而已嗎
作者:
EdisonX (卡卡獸)
2014-04-26 22:47:00就算是幫掛的,裡面的東西有掛到 c++ header 啊 @@
用tuple or vector<vector<T> >