Time of Update: 2018-12-03
/*可以使用任何類型來執行個體化該類型的參數,只要所使用的類型提供模板使用的操作即可 鑒於曆史原因,你可以使用class來代替typename,來定義型別參數。在C++語言的演化過程中typename出現的相對較晚一些,在它之前,關鍵字classs是引入型別參數的唯一方式,並一直作為有效方式保留下來。 從語義上講,class和typename是等將的。即使是template< class T> 你也可以使用任何類型來執行個體化模板參數。然而class可能給人誤導
Time of Update: 2018-12-03
// maximum of two int valuesinline int const& max (int const& a, int const& b){ return a < b ? b : a;}// maximum of two values of any typetemplate <typename T>inline T const& max (T const& a, T const& b){
Time of Update: 2018-12-03
在<TCHAR.h>標頭檔裡,有這麼一組操作檔案的宏 #define _tfdopen _wfdopen #define _tfsopen _wfsopen #define _tfopen _wfopen #define _tfopen_s _wfopen_s #define _tfreopen _wfreopen #define _tfreopen_s _wfreopen_s
Time of Update: 2018-12-03
#include <vector>#include <stdexcept>#include <iostream>#include <string>#include <cstdlib>template <typename T>class Stack {private:std::vector<T> elems; // elementspublic:void push(T const&); /
Time of Update: 2018-12-03
#include <deque>#include <string>#include <stdexcept>//#include "stack1.hpp"#include <iostream>#include <string>#include <cstdlib>#include <vector>template <typename T>class Stack { private:
Time of Update: 2018-12-03
#include <vector>#include <stdexcept>#include <iostream>#include <deque>#include <cstdlib>//std::vector<T> 是CONT的預設值(預設模板實參)template <typename T, typename CONT = std::vector<T> >class Stack
Time of Update: 2018-12-03
#include <iostream>#include <vector>// print elements of an STL containertemplate <typename T>void printcoll (T const& coll){typename T::const_iterator pos; // iterator to iterate over colltypename T::const_iterator
Time of Update: 2018-12-03
#include <vector>#include <stdexcept>#include <iostream>#include <deque>#include <cstdlib>//std::vector<T> 是CONT的預設值(預設模板實參)template <typename T, typename CONT = std::vector<T> >class Stack
Time of Update: 2018-12-03
#include <iostream>#include <cstring>#include <string>// maximum of two values of any typetemplate <typename T>inline T const& max (T const& a, T const& b){return a < b ? b : a;}// maximum of two
Time of Update: 2018-12-03
指標有兩個屬性:指向變數/對象的地址和長度 但是指標只儲存地址,長度則取決於指標的類型 編譯器根據指標的類型從指標指向的地址向後定址 指標類型不同則定址範圍也不同,例如: int*從指定地址向後尋找4位元組作為變數的儲存單元 double*從指定地址向後尋找8位元組作為變數的儲存單元void幾乎只有“注釋”和限制程式的作用 void真正發揮的作用在於:(1) 對函數返回的限定;(2) 對函數參數的限定 下面有使用void的規則:規則一 如果函數沒有傳回值,那麼應聲明為void類型規則二
Time of Update: 2018-12-03
/* 用C語言實現物件導向編程。huyelei@yeah.net 2013.01.09本程式中建立了結構體Student, 成員age和number類比類的資料成員,成員setAge,getAge和showNumber類比類的函數成員(類的方法)本程式測試方法:在VC中建立空白的Win32 Console型工程,為工程添加新源檔案main.c(若main.cpp,則使用C++編譯器) 將本程式拷貝到main.c中即可測試。*/#include
Time of Update: 2018-12-03
看看這段代碼。p = malloc(bytes);if (p == NULL )...{printf("can't allocate enough memory.
Time of Update: 2018-12-03
crack.am1:32位作業系統中 vc中char字元占幾個位元組呀 int呢 char 1,int 4,long 4,double 8注意int 在64位作業系統中是8個byte 從32位到64位通過在資料前面補零實現,工作管理員裡有*的就是32位 2:64位寫的程式和在32位上寫的程式有什麼區別?應該在64位機上更快 如果加上SSEII或SSEIII浮點運算更快3:C++中的volitile/const的用法 常量 唯讀和唯寫的關係 const修飾的變數不可修改啊 4: const
Time of Update: 2018-12-03
C++ SDK沒有直接提供動態數組功能,雖然可以使用MFC的CArray類,或者用指標+new來實現,但前者需要MFC庫,後者使用時不易理解且運行效率低,為此,我把很久前自己寫的一個簡單的動態數組類貼出來,希望給一些朋友啟發。 代碼說明:本類在數群組成員的賦值和記憶體配置上作了最佳化,對大數組的效能有明顯提高。 使用方法:將代碼複製到標頭檔CMyArray.h檔案中,在項目中引用該檔案即可。 一、標頭檔CMyArray.h#ifndef
Time of Update: 2018-12-03
第一課:C#使用WINDOW API和對記憶體的操作。這一課是些簡單的東西,瞭解的可以直接越過。考慮到大多數使用c#的人都是做網站的,可能沒有機會接觸這些,所以我在這裡做一下粗略的介紹。step 1:認識WINAPI windows系統裡提供了很多的函數,我們如果做外掛的話,就需要用到其中的函數(以下簡稱API)。(廢話:這些API被封裝在系統路徑下的DLL檔案裡。事實上,我們不用關心它在哪,我們只要知道怎麼用就可以了,)用起來很簡單,格式如下: public partial
Time of Update: 2018-12-03
我同學面google,就被問了下面的問題靜態類成員包括待用資料成員和靜態函數成員兩部分。 一 待用資料成員: 類體中的資料成員的聲明前加上static關鍵字,該資料成員就成為了該類的待用資料成員。和其他資料成員一樣,待用資料成員也遵守public/protected/private訪問規則。同時,待用資料成員還具有以下特點: 1.待用資料成員的定義。 待用資料成員實際上是類域中的全域變數。所以,待用資料成員的定義(初始化)不應該被放在標頭檔中。 其定義方式與全域變數相同。舉例如下:
Time of Update: 2018-12-03
1.求下面函數的傳回值(微軟)int func(x) { int countx = 0; while(x) { countx ++; x = x&(x-1); } return countx; } 假定x = 9999。 答案:8思路:將x轉化為2進位,看含有的1的個數。2.
Time of Update: 2018-12-03
return是C++預定義的語句,它提供了種植函數執行的一种放大。當return語句提供了一個值時,這個值就成為函數的傳回值.說到return,有必要提及主函數的定義.很多人甚至市面上的一些書籍,都使用了void main( ) ,其實這是錯誤的。C/C++ 中從來沒有定義過void main( ) 。C++ 之父 Bjarne Stroustrup 在他的首頁上的 FAQ 中明確地寫著 The definition void main( ) { /* ... */ } is not and
Time of Update: 2018-12-03
C++ primer 可謂是經典的不能在經典的一本書這本書的每一章節背後都有些術語,我按順序摘抄了些...以後補全C++ primer 術語第一章Argument 實參Block 塊Buffer 緩衝區Built-in type 內建類型Cerr CinClass 類Class type 類類型Clog Comment 注釋Condition 條件CoutCurly brace 花括弧Data structure 資料結構Edit-compile-debug
Time of Update: 2018-12-03
廢話少說,直接上代碼.h就不貼出來了 註解部分來自某博文 對理解很有協助,所以拿過來一下#include "ArraySh.h"#include <iostream>using namespace std;ArraySh::ArraySh(int size){data = new long[size];items = 0;}ArraySh::~ArraySh(){delete data;}void ArraySh::insert(long d){data[items++] =