现在的位置: 首页 > 综合 > 正文

C++_头文件和源文件

2016年08月31日 ⁄ 综合 ⁄ 共 437字 ⁄ 字号 评论关闭
//
// 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;
}

抱歉!评论已关闭.