C++中創(chuàng )建頭文件的方法
cpp通過(guò)類(lèi)名+::+函數名被頭文件鏈接。注意一定是類(lèi)名+::!
函數代碼放在cpp下的相應的函數名里,而頭文件中的只是函數名,只負責提供映射。
animal.cpp
#include "animal.h"
#include
animal::animal()
{
cout<<"hello"<
void animal::eat ()
{
cout<<"shift"<
animal.h
//頭文件只寫(xiě)函數名,提供鏈接地址。
#ifndef ANIMAL_H_H
#define ANIMAL_H_H
class animal
{
public:
animal();
void eat();
};
#endif
-------------------------------------------------------------------------------------
如果不創(chuàng )建頭文件就要寫(xiě)這么長(cháng)的代碼 可讀性很差#include
class animal
{
public:
animal()
{
cout<<"animal construct"<
}
~animal()
{
cout<<"construct animal"<
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
}
virtual void breath()
{
cout<<"bubble2"<
}
void eat();//把主函數放在類(lèi)外的方法
};
class fish:public animal
{
public:
fish()
{
}
~fish()
}
void breath()
{
}
};
void animal::eat()//函數類(lèi)型,屬于那個(gè)類(lèi)。把一個(gè)函數的實(shí)現放到類(lèi)之外。
{
}
void main()
{
}
關(guān)鍵詞:
C++頭文
相關(guān)推薦
-
-
-
-
-
-
-
xiaohua | 2002-08-16
技術(shù)專(zhuān)區
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線(xiàn)
- 開(kāi)關(guān)電源
- 單片機
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開(kāi)發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機控制
- 藍牙
- PLC
- PWM
- 汽車(chē)電子
- 轉換器
- 電源管理
- 信號放大器
評論