1、#pragma once
#pragma once
#include<iostream>
using namespace std;
class Student
{
public:
Student()
{
cout << "I am a student." << endl;
}
};
#pragma once
//#include<iostream>
#include "student.h"
//using namespace std;
class School
{
public:
School()
{
cout << "This is a school." << endl;
Student stu;
}
};
#include "student.h"
#include "school.h"
int main()
{
Student a;
School b;
return 0;
}
I am a student.
This is a school.
I am a student.
2、#ifndef xx #define xx xxxx #endif
#include<iostream>
using namespace std;
#ifndef _STUDENT_H
#define _STUDENT_H
class Student
{
public:
Student()
{
cout << "I am a student." << endl;
}
};
#endif // !_STUDENT_H
//#include<iostream>
#include "student.h"
//using namespace std;
#ifndef _SCHOOL_H
#define _SCHOOL_H
class School
{
public:
School()
{
cout << "This is a school." << endl;
Student stu;
}
};
#endif // !_SCHOOL_H
#include "student.h"
#include "school.h"
int main()
{
Student a;
School b;
return 0;
}
I am a student.
This is a school.
I am a student.
·引用
**平时都是在别人的项目代码基础上加自己的内容,其实他们的头文件也有,没注意到,可惜。