【发布时间】:2019-10-03 04:21:16
【问题描述】:
我希望在一个类中初始化一个多维动态数组。但是,我遇到了一个错误。
我在网上看过几个例子。他们似乎很难。我是编码新手。如果可能的话,我想要一个简单的解决方案。
class myp
{
int ntc = 5;
public:
double** y = new double*[ntc];
for(int i = 0; i < ntc; ++i)
y[i] = new int[3];
};
int main()
{
int x;
myp mp;
mp.y[1][1] = 3;
cout<<mp.y[1][1]<<endl;;
return 0;
}
test.cpp:12:2: error: expected unqualified-id before ‘for’
for(int i = 0; i < ntc; i++)
^~~
test.cpp:12:17: error: ‘i’ does not name a type
for(int i = 0; i < ntc; i++)
^
test.cpp:12:26: error: ‘i’ does not name a type
for(int i = 0; i < ntc; i++)
【问题讨论】: