student.cpp
来自「C++课程更学习...对于初学者很有好出」· C++ 代码 · 共 58 行
CPP
58 行
// Student.cpp: implementation of the CStudent class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include "Student.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CStudent::CStudent() // 默认构造
{
m_sName = NULL;
m_nID = 0;
m_nAge = 0;
printf("默认构造调用了\n");
}
CStudent::CStudent(char sName[], int nID, int nAge)
{
m_sName = new char[strlen(sName) + 1];
strcpy(m_sName, sName);
m_nID = nID;
m_nAge = nAge;
}
CStudent::CStudent(CStudent& stu) // 拷贝构造
{
m_sName = new char[strlen(stu.m_sName) + 1];
strcpy(m_sName, stu.m_sName);
////
m_nID = stu.m_nID;
m_nAge = stu.m_nAge + 10;
printf("拷贝构造调用了!\n");
}
CStudent::~CStudent()
{
if (m_sName != NULL)
{
delete [] m_sName;
m_sName = NULL;
}
printf("析构函数调用了\n");
}
void CStudent::Show()
{
printf("姓名:%s,ID:%d,年龄:%d\n",
this->m_sName,
this->m_nID,
this->m_nAge);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?