请问各位:在vc++中怎样定义动态数组。
还有我写了如下的代码,为什么也定义不了普通的数组??
float zhuanzhi(float k[];int weishu)
{
const int nn=weishu
float shuzu[nn][nn];
//我是想定义一个未知数nn维的数组。
}
你可以这么写
int weishu;
cin>>weishu;
const int nn = weishu;
float shuzu[nn][nn];
我已经试过了,你说的方法不可行。下面是报错。
:\Documents and Settings\xxrrdd\dongtaishuzu.cpp(9) : error C2057: expected constant expression
C:\Documents and Settings\xxrrdd\dongtaishuzu.cpp(9) : error C2466: cannot allocate an array of constant size 0
C:\Documents and Settings\xxrrdd\dongtaishuzu.cpp(9) : error C2057: expected constant expression
C:\Documents and Settings\xxrrdd\dongtaishuzu.cpp(9) : error C2466: cannot allocate an array of constant size 0
C:\Documents and Settings\xxrrdd\dongtaishuzu.cpp(9) : error C2087: '<Unknown>' : missing subscript
C:\Documents and Settings\xxrrdd\dongtaishuzu.cpp(9) : error C2133: 'shuzu' : unknown size
Error executing cl.exe.
[此贴子已经被作者于2006-4-11 18:32:00编辑过]