⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 student.cpp

📁 C++课程更学习...对于初学者很有好出
💻 CPP
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -