亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码

專注電子技術學習與研究
當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

C++中創建頭文件的方法

作者:黃波海   來源:本站原創   點擊數:  更新時間:2014年03月07日   【字體:

 創建頭文件。(不帶形參)
cpp通過類名+::+函數名被頭文件鏈接。注意一定是類名+::!
函數代碼放在cpp下的相應的函數名里,而頭文件中的只是函數名,只負責提供映射。
animal.cpp
#include "animal.h"
#include <iostream.h>
animal::animal()
{
   cout<<"hello"<<endl;
}
void animal::eat ()
{
   cout<<"shift"<<endl;
}


animal.h
//頭文件只寫函數名,提供鏈接地址。
#ifndef ANIMAL_H_H
#define ANIMAL_H_H
class animal
{
  public:
  animal();

void eat();
};
#endif

-------------------------------------------------------------------------------------

如果不創建頭文件就要寫這么長的代碼 可讀性很差#include<iostream.h>

class animal
{
public:
animal()
{
cout<<"animal construct"<<endl;
}
~animal()
{
cout<<"construct animal"<<endl;
}
virtual void breath()  
{
cout<<"bubble2"<<endl;
}
void eat();//把主函數放在類外的方法
};
class fish:public animal 
{
public:
fish()
{
 
}
~fish()
 
}
void breath()
{   
}
};
void animal::eat()//函數類型,屬于那個類。把一個函數的實現放到類之外。
{
 
}
 
void main()
{
 
}
關閉窗口

相關文章