求大神看看我的这段程序出了什么毛病,#includeusing namespace std;class Employee{public:\x05Employee(int pId,char* pName,int pAge);\x05~Employee();\x05friend class Manager;private:\x05int id;\x05char* name;\x05int age;};class Manager{pu

来源:学生作业帮助网 编辑:作业帮 时间:2024/12/02 17:27:34
求大神看看我的这段程序出了什么毛病,#includeusing namespace std;class Employee{public:\x05Employee(int pId,char* pName,int pAge);\x05~Employee();\x05friend class Manager;private:\x05int id;\x05char* name;\x05int age;};class Manager{pu
xVMOA+cLVh!^-Q aw(N`!QM4ƃNLwٙvQ/μ̼m3G-7^vć_[QE>oGoV/bbڡB6 A M2L>vgU7ٸsv%+cU5w ]m@H,_/x ط m`X[ ˣ&E5C5ɱg)lQD3lU_ GUf!M

求大神看看我的这段程序出了什么毛病,#includeusing namespace std;class Employee{public:\x05Employee(int pId,char* pName,int pAge);\x05~Employee();\x05friend class Manager;private:\x05int id;\x05char* name;\x05int age;};class Manager{pu
求大神看看我的这段程序出了什么毛病,
#include
using namespace std;
class Employee
{
public:
\x05Employee(int pId,char* pName,int pAge);
\x05~Employee();
\x05friend class Manager;
private:
\x05int id;
\x05char* name;
\x05int age;
};
class Manager
{
public:
\x05Manager(int pId,char* pName,int pAge);
\x05~Manager();
\x05void Manager::printEmployee(Employee&employee);
private:
\x05int id;
\x05char* name;
\x05int age;
};
Manager::Manager(int pId,char* pName,int pAge)
{
\x05id=pId;
\x05name=new char[strlen(pName)+1];
\x05if(name!=0)
\x05 strcpy(name,pName);
\x05age=pAge;
\x05cout

求大神看看我的这段程序出了什么毛病,#includeusing namespace std;class Employee{public:\x05Employee(int pId,char* pName,int pAge);\x05~Employee();\x05friend class Manager;private:\x05int id;\x05char* name;\x05int age;};class Manager{pu
m打错了 应该是m1吧
你定义的是m1 调用的是m


修改后
#include<iostream>
#include<cstring>
using namespace std;

class Employee
{
public:
\x05Employee(int pId,char* pName,int pAge);
\x05~Employee();
\x05friend class Manager;
    
private:
\x05int id;
\x05char* name;
\x05int age;
};
class Manager
{
public:
\x05Manager(int pId,char* pName,int pAge);
\x05~Manager();
\x05void printEmployee(Employee&employee);
private:
\x05int id;
\x05char* name;
\x05int age;
};
Manager::Manager(int pId,char* pName,int pAge)
{
\x05id=pId;
\x05name=new char[strlen(pName)+1];
\x05if(name!=0)
\x05   strcpy(name,pName);
\x05age=pAge;
\x05cout<<"Contructed with all parameters."<<endl;
}
Employee::Employee(int pId,char* pName,int pAge)
{
\x05id=pId;
\x05name=new char[strlen(pName)+1];
\x05if(name!=0)
\x05   strcpy(name,pName);
\x05age=pAge;
\x05cout<<"Contructed with all parameters."<<endl;
}
Manager::Manager()
{
\x05delete[] name;
\x05cout<<"Decontructed."<<endl;
}
Employee::Employee()
{
\x05delete[] name;
\x05cout<<"Decontructed."<<endl;
}
void Manager::printEmployee(Employee&employee)
{
\x05cout<<"id:"<<employee.id<<","<<"name:"<<employee.name<<","<<"age:"<<employee.age<<endl;
}
int main()
{
\x05Manager m1(1001,"zhangsan",22);
\x05Employee e1(1003,"maliu",23);
\x05m1.printEmployee(e1);
\x05return 0;
}