|
按照老师的编程,检查了好几遍,就是不晓得为啥会这样
#pragma once
#include<iostream>
#include <string>
using namespace std;
class Student
{
public:
char *p_name;
char sex;
int num;
int age;
Student(char* pname, char t_sex, int t_num, int t_age);
~Student();
};
#include "CStudent.h"
#include<iostream>
#include <string>
Student::Student(char* pname, char t_sex, int t_num, int t_age):sex(t_sex), num(t_num), age(t_age)
{
if (pname)
{
int n_len = strlen(pname);
p_name = new char[n_len + 1];
memset(p_name, 0, n_len + 1);
strcpy(p_name, pname);
}
}
Student::~Student()
{
if (p_name)
{
delete[] p_name;
p_name = NULL;
}
}
#include<iostream>
#include <string>
#include"CStudent.h"
using namespace std;
void test()
{
Student stud("zhangsan", 'f', 1001, 20);
}
int main()
{
Student *szhang_san=new Student ("zhangsasdfafafaan",'f',1001,20);
return 0;
}
error C2664: “Student::Student(const Student &)”: 无法将参数 1 从“const char [12]”转换为“char *”
|
上一篇: visual studio 2017下一篇: 类的继承与派生中无法解析的外部命令问题
|