如何在类的私有成员中定义二维数组并初始化
比如说这个#include"stdafx.h"#include"lab5_2.h"#include<iostream>usingnamespacestd;classCLI...
比如说这个
#include "stdafx.h"
#include"lab5_2.h"
#include<iostream>
using namespace std;
class CLIENT
{
public:
static void CHangeServerName()
{
cin>>ServerName[1];
}
void add()
{
ClientNum++;
}
void show()
{
cout<<ServerName[1]<<" ClientNum is
"<<ClientNum<<endl;
}
private:
static char ServerName[3][25];
static int ClientNum;
};
char CLIENT::ServerName[3][25]="CLIENT";//wrong
int CLIENT::ClientNum=0;
int client()
{
int num;
char ch;
CLIENT Client;
cout<<"do you want to change de name of CLIENT y
or N"<<endl;
cin>>ch;
if(ch=='y'||ch=='Y')
{
Client.CHangeServerName();
}
cout<<"how many ClientNum do you want to
add"<<endl;
cin>>num;
for(int i=0;i<num;i++)
{
Client.add();
}
Client.show();
return 0;
} 展开
#include "stdafx.h"
#include"lab5_2.h"
#include<iostream>
using namespace std;
class CLIENT
{
public:
static void CHangeServerName()
{
cin>>ServerName[1];
}
void add()
{
ClientNum++;
}
void show()
{
cout<<ServerName[1]<<" ClientNum is
"<<ClientNum<<endl;
}
private:
static char ServerName[3][25];
static int ClientNum;
};
char CLIENT::ServerName[3][25]="CLIENT";//wrong
int CLIENT::ClientNum=0;
int client()
{
int num;
char ch;
CLIENT Client;
cout<<"do you want to change de name of CLIENT y
or N"<<endl;
cin>>ch;
if(ch=='y'||ch=='Y')
{
Client.CHangeServerName();
}
cout<<"how many ClientNum do you want to
add"<<endl;
cin>>num;
for(int i=0;i<num;i++)
{
Client.add();
}
Client.show();
return 0;
} 展开
2个回答
展开全部
给你一个例子看看 如何初始化二维数组
class AA
{
public:
int INTarray[3][25];
AA()//构造函数中初始化
{
for (int i=0;i<3;i++)
{
for (int j=0;j<25;j++)
{
INTarray[i][j]=5;//把二维数组中的值都设置成5
}
}
}
};
class AA
{
public:
int INTarray[3][25];
AA()//构造函数中初始化
{
for (int i=0;i<3;i++)
{
for (int j=0;j<25;j++)
{
INTarray[i][j]=5;//把二维数组中的值都设置成5
}
}
}
};
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询