C 快速入門 3

2021-08-16 05:11:46 字數 1155 閱讀 3662

乙個.h檔案只能被編譯一次,如果你在多個檔案中包含,那就會被編譯多次,從而程式出錯,那麼在c中,你可以這樣來控制只包含一次

#ifndef _programe

#define _porgrame

//這裡寫定義的內容

typedef struct nodenode;

#endif

通過如上方法,不過你引入這個標頭檔案幾次,編譯器都只會編譯一次,而在c++中只需要引入乙個指令就能達到同樣的效果

#pragram once

typedef struct nodenode;

在c++中同通常不會把類的實現和類的屬性放到一起,而是分開實現,如果將函式和屬性放到一起,編譯器自動把函式轉換成內聯函式,之前的helloword中,介紹了如下的實現方式

class teacher;

include "teacher.h"

void teacher::setage(int age)

int teacher::getage()

//main函式中使用

#include "teacher.h"

int main()

int gets();

bool iscontainpoint(point &point);

};#include "circle.h"

void circle::setr(int r)

int circle::getr()

int circle::gets()

bool circle::iscontainpoint(point &point)else

}class point

void point::seta(int a)

void point::setb(int a)

#include "iostream"

#include "circle.h"

#include "point.h"

using namespace std;

int main()

}

韋東山 C 快速入門 基礎3

person p new person delete p person pers new person 10 delete pers 靜態資料成員 point operator cont point p1,cont point p2 p1,p2相加 靜態成員函式 point operator con...

Python快速入門(3)

資料結構 列表的元素可變,用 or list 建立。元祖的元素不可變,用 or tuple 建立。集合的元素不可重複,用 or set 建立。字典的存放k v,用dict or 建立。del 按照索引 刪除資料結構元素 or 變數 list list.extend l a len a l list....

C 快速入門

1.1 呼叫 gnu編譯器的預設命令是 g g prog.cc o prog unix 的 shell視窗 cc prog.cc 標準的輸入與輸出物件 處理輸入時使用的命令 cin cin為 istream型別物件 處理輸出時使用的命令 cout cout為 ostream型別物件 標準庫的另外兩個...