原创 c++ (virtual)虛函數

什麼是虛函數1.      當我們提到虛函數或虛方法時,我們通常指會指的是在繼承或多態的背影下,基類虛函數的行爲可以背子類定製。2.      虛函數與非函數的最大區別是,虛函數是在運行時根據調用對象的不同動態邦定的;而非虛數是在編譯時就

原创 c++ 數據類型轉換(RTTI)

運行時類型實別(RTTI) RTTI 是 Run-time Type Identification 的縮寫。RTTI爲程序提供了一個標準方式用來在運行時決定對象的類型。也就是說RTTI允許指向基類的對象或引用在運行時恢復到其實際指的子類類

原创 c++ 類型轉換

類型轉換操作 a = dynamic_cast<T*>(p) Try to convert p into a T*. It may return 0 a = dynamic_cast<T&>(*p) Try to convert *p

原创 c++ 內存管理

自動內存管理 在介紹自動手功內存管理之前,我們先介紹一下自動內存管理。 自動內存管理與局部變量相關,當程序執行時看到變量定義時,一個局部變量就開始佔

原创 c++ 單鏈表的基本操作

#include <iostream> using namespace std; struct Node { int data; Node* next; }; // only for the 1st Node void init

原创 c++ 二叉樹示例

/* Binary Tree */ #include <iostream> #include <deque> #include <climits> using namespace std; struct Tree { char da

原创 單鏈表相關操作代碼

#include <iostream> #include <cassert> using namespace std; struct node{ int data; // data struct n

原创 operator << 做爲 virtual 重載問題

#include <iostream> using namespace std; class fig2d { int dim1; int dim2; public: fig2d(){dim1 = 5,dim2

原创 兩種字符串逆序方式

#include <iostream> #include <cstring> using namespace std; void swap(char &a, char &b) { a = a^b; b = a^b;

原创 冒泡排序、插入排序及快速排序

#include <iostream> #include <vector> #include <ctime> #include <cstdlib> #include <algorithm> using namespace std; //

原创 c++ 指針操作1

內存泄露與破壞 C++的兩個主要問題就是內存泄露與損害.內存泄露是指內存審請後沒有釋放,這種方式導致內存內存浪費最終可能會發生內存不夠的錯誤.內存損壞是發生在程序將數據寫在錯誤的內存位置,重寫了那壞內存數

原创 一年又一年變成大齡程序員

最近一直在對新技術進行嘗試,從J2EE,PHP,Android,IOS,python,golang 反覆折騰了一兩個月。感覺還是對後臺數據分析部分感興趣,自認爲對c++還算了解,現在確定嘗試從做了4年多的

原创 詳解c/c++函數指針

要理解一個C程序,僅僅理解組成該程序的符號是不夠的。程序員還必須理解這些符號是如何組合成聲明、表達式、語句和程序的。      我們先來看看下面的一個語句: ? 1 ( *( void(*)())0

原创 c++ 設計模式之 單例模式

概念 單例模式是確保一個變量只有一個實例,並提供一個全局的角度進行訪問. 類圖 示例代碼 #include <iostream> using namespace std; class Singleton { public: st

原创 c++ 模板

模板函數 模板函數例子如下: #include <iostream> template <class T> const T& min(const T& a, const T& b) { return a < b ? a : b; }