第二十一章,析構函數初探(C++)

NPC.h

#ifndef NPC_H
#define NPC_H
#include <string>

class NPC
{
	public:
		//構造函數 
		NPC();
		//析構函數 
		~NPC();
		
	protected:
};

#endif
NPC.cpp

#include "npc.h"
#include <iostream>

//構造函數 
NPC::NPC(){
	std::cout<<"初始化。。。"<<std::endl; 
}
//析構函數 
NPC::~NPC(){
	std::cout<<"結束。。。"<<std::endl; 
}
main.cpp

#include <iostream>
#include "NPC.h"

int main(int argc, char** argv) {
	NPC npc;
	return 0;
}
調試截圖:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章