c++ const 二维数组成员如何初始化? 5
classA{private:constcharc[7][7];public:A(){cout<<"Astructor"<<endl;}};如何初始化二维数组c?#inc...
class A{
private:
const char c[7][7];
public:
A()
{
cout<<"A structor"<<endl;
}
};
如何初始化二维数组c?
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout<<"A structor"<<endl;
}
static const char c[7][7];
private:
};
const char A::c[7][7] = {{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'}};
int main()
{
for(int i=0;i<7;i++)
{
for(int j=0;j<7;j++)
{
cout<<A::c[i][j]<<",";
}
cout<<endl;
}
getchar();
return 0;
} 展开
private:
const char c[7][7];
public:
A()
{
cout<<"A structor"<<endl;
}
};
如何初始化二维数组c?
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout<<"A structor"<<endl;
}
static const char c[7][7];
private:
};
const char A::c[7][7] = {{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'},
{'1','2','3','4','5','6','7'}};
int main()
{
for(int i=0;i<7;i++)
{
for(int j=0;j<7;j++)
{
cout<<A::c[i][j]<<",";
}
cout<<endl;
}
getchar();
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询