**:
定義了乙個#include
using
namespace
std;
class animal
};class dog : public animal
};int main()
animal
類,派生類dog
,如果不使用指標或引用,baddog
的型別永遠是animal
型別,而不會是別的型別。animal baddog = dog()
將乙個新的dog
物件複製到baddog
, 由於baddog
只是animal
型別,只會將dog
物件進行切片,取屬於animal
的部分,稱為切片(slicing)。
[1]
C 多型的乙個例子
class a virtual void f2 static void f3 virtual void f4 class b virtual void f2 static void f3 virtual void f4 int main 執行結果 a f1 b f1 a f3 b f2 分析 類的成...
C實現shell管理的乙個例子
通常情況下,乙個程序 比如cat tmp tt.txt 的輸出與輸入是標準輸入 stdin或者0 標準輸出 stdout或者1 shell 獲取tt.txt檔案中包含aa的行記錄,涉及兩個程序,乙個讀檔案,乙個過濾 cat tmp tt.txt grep aa aa該方式的實現用到管道符,管道讓乙個...
乙個例子理解C 位移
來自 很多人覺得位移這東西很複雜,二進位制一堆0 1看不懂。其實很簡單。位移理解可能簡單一些 其實位移就是資料轉換成二進位制的左右移動 右移左補0,左移右補0,後面多出來的部分去掉。用乘除法去理解位移也可以 左位移 相當於乘 左移1位相當於乘2,左移2位相當於乘4,左移3位相當於乘8,左移4位相當於...