//定义头文件和声明类,但是没有给出实现的具体方法,在项目中会编译链接到所需要的方法中
#ifndef CXG_H
#define CXG_H#include<string> //自定义库文件函数
using namespace std;
class print{
public:
void welcome();
private:
string str1;
};
#endif
//具体的实现方法
#include<iostream>
using namespace std;
class print{
public:
void welcome(){
printf("welcome");
return;
}
private:
string str1="welcom";
};
//程序入口
#include<iostream>
#include "2.h"
using namespace std;
int main(){
print p;
p.welcome();
return 0;
}
//一个文件最好包含一个类,可以在类里面定义main程序入口检测类(java)