标题:c++中的动态数组
取消只看楼主
xurundong
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-4-10
 问题点数:0 回复次数:1 
c++中的动态数组

请问各位:在vc++中怎样定义动态数组。
还有我写了如下的代码,为什么也定义不了普通的数组??
float zhuanzhi(float k[];int weishu)
{
const int nn=weishu

float shuzu[nn][nn];
//我是想定义一个未知数nn维的数组。
}

搜索更多相关主题的帖子: 动态 
2006-04-11 14:09
xurundong
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-4-10
得分:0 
以下是引用gototheworld在2006-4-11 16:52:00的发言:

你可以这么写
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编辑过]

2006-04-11 18:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-56779-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.119286 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved