C++_头文件和源文件

来源:互联网 发布:树莓派 重启网络 编辑:程序博客网 时间:2024/05/21 14:06
//// Human.h  // 头文件//#ifndef HUMAN_H_INCLUDED#define HUMAN_H_INCLUDED#include <iostream>class Human{public:    void SetHeight(int);    int GetHeight();private:    int height;};#endif // HUMAN_H_INCLUDED


//// Human.cpp  // 源文件//#include "Human.h"void Human::SetHeight(int x){    height = x;}int Human::GetHeight(){    return height;}

//// main.cpp//#include <iostream>#include "Human.h"int main(){    Human Mike;    Mike.SetHeight(180);    std::cout << "Mike的身高:" << Mike.GetHeight() << std::endl;    return 0;}





0 0
原创粉丝点击