首页 > 编程语言 > 详细

第二十章,对象指针及this的使用(C++)

时间:2015-06-15 11:13:22      阅读:136      评论:0      收藏:0      [点我收藏+]

NPC.h

#ifndef NPC_H
#define NPC_H
#include <string>
class NPC
{
	public:
		std::string name;
		int age;
		void desc();
		 
	protected:
};

#endif

NPC.cpp

#include "npc.h"
#include <iostream>
void NPC::desc(){
	std::cout<<"name:"<<this->name<<",age:"<<this->age<<std::endl;
}
main.cpp

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

int main(int argc, char** argv) {
	
	NPC n,*npc;
	npc =&n;
	n.age=10;
	npc->name="npc001";
	npc->desc();
	return 0;
}
调试截图:

技术分享

第二十章,对象指针及this的使用(C++)

原文:http://blog.csdn.net/qingbowen/article/details/46500839

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!