严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. Clientl 类实验 C:\Users\20892\source\repos\Clientl 类实验\源.cpp 9
将strcpy改成strcpy_后还是不行
#include<iostream>
using namespace std;
class Client
{
public:
Client()
{
m_name = new char[20];
strcpy_s(m_name, "noname");
m_age = 0;
m_type = 0;
}; //无参初始化
Client(const char *pname, int age, int type)
{
m_name = new char[strlen(pname) + 1];
strcpy_s(m_name, pname);
m_age = age;
m_type = type;
} //有参初始化
~Client()
{
delete[] m_name;
}
void SetName(const char* pname)
{
delete[]m_name;
m_name = new char[strlen(pname) + 1];
strcpy_s(m_name, pname);
} //设置姓名
char *GetName()
{
return m_name;
}
void SetType(int type)
{
m_type = type;
}
int GetType()
{
return m_type;
}
void SeTage(int age)
{
m_age = age;
}
int GetAge()
{
return m_age;
}
Client(Client& obj)
{
m_type = obj.GetType();
m_age = obj.GetAge();
m_name = new char[strlen(obj.GetName())+1];
strcpy_s(m_name, obj.GetName());
}
private:
char *m_name;
int m_age;
int m_type;
};
void display(Client x)
{
cout << "名字为:" << x.GetName() << " 类型为:" <<
x.GetType() << " 年龄为:" << x.GetAge() << endl;
}
int main()
{
Client c1, c2("panjiang", 19, 3);
c1.SetName("liming");
c1.SeTage(20);
c1.SetType(2);
display(c1);
display(c2);
return 0;
}