**Student.h**
** //这是抽象文件的代码**//学生-基础学生抽象文件将链接到实现文件,以创建一个显示学生姓名和ID的程序
#ifndef _STUDENT_
#define _STUDENT_
namespace Schools
{
class Student
{
public:
Student(char* pszName, int nID);
virtual char* display()
protected:
** //学生姓名**
char* pszName;
int nID;
};
}
#endif
**//Student.cpp**
**// this is the code of the implementation file**
**// Student - implementation of student**
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include "Student.h"
namespace Schools
{
Student::Student(char* pszNameArg, int nIDArg): nID(nIDArg)
//create an array
pszName = new char[strlength(pszNameArg) + 1];
strcpy(pszName, pszNnameArg);
}
** //显示功能-显示学生的描述**
char* Student::display()
{
pReturn = new char[strlength(pszName) + 1];
strcpy(pReturn, pszName);
return pReturn;
}
在此处输入代码
如果只删除明显的错别字和错误,您的代码将起作用:
// Student.h
#ifndef _STUDENT_
#define _STUDENT_
namespace Schools
{
class Student
{
public:
Student(char* pszName, int nID);
virtual char* display();
protected:
char* pszName;
int nID;
};
}
#endif
// Student.cpp
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include "Student.h"
namespace Schools
{
Student::Student(char* pszNameArg, int nIDArg): nID(nIDArg)
{
//create an array
pszName = new char[strlen(pszNameArg) + 1];
strcpy(pszName, pszNameArg);
}
char* Student::display()
{
char* pReturn = new char[strlen(pszName) + 1];
strcpy(pReturn, pszName);
return pReturn;
}
}