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; }
调试截图:
时间: 2024-10-17 03:01:40