方法1:类的头文件中写#pragma once class MyTeacher { public: MyTeacher(); ~MyTeacher(); };方法2:类的头文件中写#ifndef _MYTEACHER_H_ #define _MYTEACHER_H_ class MyTeacher { public: MyTeacher(); ~MyTeacher(); }; #endif