// 202032.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iomanip>
#include<iostream>
using namespace std;
class Employee{
public:
Employee(char*const na[10],int n);
Employee();
static void PrintTotal();
void PrintInfo();
~Employee();
private:char name[10];
int num;
static int total;
};
int Employee::total=0;
Employee stu1("李华",001);
void Fun();
int _tmain(int argc, _TCHAR* argv[])
{
Employee::PrintTotal();
Fun();
Employee s[3];
int i;
cout<<endl;
for(i=0;i<3;i++)
s[i].PrintInfo();
Employee::PrintTotal();
return 0;
}
Employee::Employee(){
cout<<"这里是构造函数"<<endl;
cout<<"输入职工姓名和编号:"<<endl;
cin>>name>>num;
total++;
}
void Employee::PrintTotal(){
cout<<endl<<"总人数:"<<total<<endl;
}
void Employee::PrintInfo(){
cout<<"姓名"<<name<<setw(7)<<"编号:"<<num<<endl;
}
Employee::~Employee(){
cout<<"这里是析构函数"<<endl;
}
void Fun()
{
static Employee stu2("李梅",002);
Employee stu3("张娜",003);
}
const char[5]相当于一个字符串,而char * const[]相当于字符串数组,当然不能直接传递了
只有一个构造函数吗?
Employee(char*const na[10],int n);
构造函数这里,char * const na[10]表示na中的元素都是字符指针,而你实际要的na是一个字符数组(元素都是字符),所以改成:
Employee(char const na[10],int n);
或者
Employee(char*const na,int n);