久久ER99热精品一区二区-久久精品99国产精品日本-久久精品免费一区二区三区-久久综合九色综合欧美狠狠

新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > C++中創(chuàng)建頭文件的方法

C++中創(chuàng)建頭文件的方法

作者: 時(shí)間:2016-12-01 來(lái)源:網(wǎng)絡(luò) 收藏
創(chuàng)建頭文件。(不帶形參)

cpp通過(guò)類(lèi)名+::+函數(shù)名被頭文件鏈接。注意一定是類(lèi)名+::!
函數(shù)代碼放在cpp下的相應(yīng)的函數(shù)名里,而頭文件中的只是函數(shù)名,只負(fù)責(zé)提供映射。
animal.cpp
#include "animal.h"
#include
animal::animal()
{
cout<<"hello"<}
void animal::eat ()
{
cout<<"shift"<}

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

void eat();
};
#endif

本文引用地址:http://cqxgywz.com/article/201612/324422.htm

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

如果不創(chuàng)建頭文件就要寫(xiě)這么長(zhǎng)的代碼 可讀性很差#include

class animal
{
public:
animal()
{
cout<<"animal construct"<
}
~animal()
{
cout<<"construct animal"<
}
virtual void breath()
{
cout<<"bubble2"<
}
void eat();//把主函數(shù)放在類(lèi)外的方法
};
class fish:public animal
{
public:
fish()
{
}
~fish()
}
void breath()
{
}
};
void animal::eat()//函數(shù)類(lèi)型,屬于那個(gè)類(lèi)。把一個(gè)函數(shù)的實(shí)現(xiàn)放到類(lèi)之外。
{
}
void main()
{
}


關(guān)鍵詞: C++頭文

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉