码迷,mamicode.com
首页 > 编程语言 > 详细

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

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

标签:c++   this   对象   指针   

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++)

标签:c++   this   对象   指针   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!