为什么employee的构造函数的形参要const char*,为什么不能是char*
#include <iostream>
using namespace std;
class employee
{
private:
string name;
string city;
string address;
string id;
public:
void display();
employee(const char* n, const char* c,const char * a, const char* i);
void changename(string* c);
};
void employee::display() {
cout << name << " " << city << endl;
cout << address << " " << id << endl;
}
void employee::changename(string* c)
{
name = *c;
}
employee::employee(const char* n, const char* c, const char* a, const char* i)
{
name = *n;
city = *c;
address = *a;
id = *i;
cout << "创建了一个employee" << endl;
};
int main()
{
employee p1("guy","guyg","huihy","hu");
return 0;
}
...全文
相关推荐
有关c ++的题目,关于构造函数和拷贝构造函数的知识点
} employee(const employee &e) { strcpy(name, e.name); strcpy(address, e.address); strcpy(post, e.post
c++继承初步学习
**示例**:```cppclass CEmployee {public: CEmployee(int id, const char* name, const char* depart) : m_ID(
onlinjudge实验题
在构造函数中,我们使用new char[]来动态分配内存以存储姓名,并使用strcpy函数将姓名拷贝到该内存中。同时,我们还将年龄初始化为参数Age的值。
C++面向对象复习题.doc
* 函数参数传递:在C++中,函数参数可以通过值传递或引用传递,实现不同的函数调用行为。* 運算符優先級:在C++中,運算符具有不同的優先級,影響了運算符的執行順序。
c++课件(4)静态成员和友元函数
**示例**: ```cpp class Employee { public: Employee(const char* name_str); static void acc_total(float f


