Time of Update: 2018-12-05
找工作前應該把C++ Primer 看好啊,發現好多筆試題就是從這本書中出的!一模一樣,失算了 :) 程式是針對問題而編寫,目的就是為解決問題,對大問題,解決的策略是:分而治之,逐步求精。在C++標準庫中定義的名字,如cout,不能直接使用,需要在程式開頭使用前置處理器指示符:#include <iostream>並要求在後面加上語句: using namespace std;標頭檔為防止重複處理,一般通過前置處理器防止重複定義,如在檔案 a.h中使用:#ifndef A_H#
Time of Update: 2018-12-05
chain.h#pragma once#include <QDebug>class CHandle{public:CHandle():m_handle(0){}CHandle(CHandle *hadle):m_handle(hadle){}virtual ~CHandle(){if (m_handle){delete m_handle;}}virtual void handleRequest() = 0;virtual void setHandle(CHandle* handle)
Time of Update: 2018-12-05
Bridge模式使得抽象和實現能夠相對獨立。bridge.h#pragma once#include <QDebug>class CImplementor{public:virtual void operateImp() = 0;};class CRectImplementor : public CImplementor{public: CRectImplementor(){}void operateImp(){ qDebug() << "this is a Rect";
Time of Update: 2018-12-05
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;using System.Threading;namespace createfile{ unsafe
Time of Update: 2018-12-05
C中CONST的使用: 雖然這聽起來很簡單,但實際上,const的使用也是c語言中一個比較微妙的地方,微妙在何處呢?請看下面幾個問題。 問題:const變數 & 常量 為什麼下面的例子在使用一個const變數來初始化數組,ANSI C的編譯器會報告一個錯誤呢? const int n = 5; int a[n]; 答案與分析: 1)、這個問題討論的是“常量”與“唯讀變數”的區別。常量肯定是唯讀,例如5,
Time of Update: 2018-12-05
C++語言支援函數重載,C 語言不支援函數重載。函數被C++編譯後在庫中的名字與C 語言的不同。假設某個C函數的聲明如下:void foo(int x, int y);該函數被C編譯器編譯後在庫中的名字為_foo,而C++編譯器則會產生像_foo_int_int之類的名字用來支援函數重載和型別安全串連。由於編譯後的名字不同,C++程式不能直接調用C函數。C++提供了一個C串連交換指定符號extern“C”來解決這個問題。例如:extern “C”{ void foo(int x, int
Time of Update: 2018-12-05
strcpy:將原串拷貝到目的串,不拷貝NULL 以下為具體實現:#include<stdio.h>#include<stdlib.h>#include<string.h>char * strcpy(char * strDest, const char * strSrc){ if(NULL == strSrc || NULL == strDest){ return NULL; } char* dest
Time of Update: 2018-12-05
一般我們進行成員變數初始化用兩種方法 第一種是通過在建構函式內賦值 class Point{public:Point(){ _x = 0; _y = 0;};Point( int x, int y ){ _x = 0; _y = 0; }private:int _x, _y;}; 第二種是使用初始化列表 class Point{public:Point():_x(0),_y(0){};Point( int x, int y ):_x(x),_y(y){}private:int _x, _y;};
Time of Update: 2018-12-05
標準c++中主要有四種強制轉換類型運算子: const_cast,reinterpret_cast,static_cast,dynamic_cast等等。 1)static_cast<T*>(a) 將地址a轉換成類型T,T和a必須是指標、引用、算術類型或枚舉類型。 運算式static_cast<T*>(a), a的值轉換為模板中指定的類型T.在運行時轉換過程中,不進行類型檢查來確保轉換的安全性。 例子: class B { ... }; class D :
Time of Update: 2018-12-05
1、靜態全域變數定義:在全域變數前,加上關鍵字 static 該變數就被定義成為了一個靜態全域變數。特點:A、該變數在全域資料區分配記憶體。B、初始化:如果不顯式初始化,那麼將被隱式初始化為0。C、訪變數只在本源檔案可見,嚴格的講應該為定義之處開始到本檔案結束。D、檔案範圍下聲明的const的常量預設為static儲存類型。2、靜態局部變數定義:在局部變數前加上static關鍵字時,就定義了靜態局部變數。特點:A、該變數在全域資料區分配記憶體。B、初始化:如果不顯式初始化,那麼將被隱式初始化為0
Time of Update: 2018-12-05
《Singleton.h》#include<iostream>#include<string>using namespace std;class A{public: static A* GetInstance(); void ShowAddress();private:A();virtual ~A();static A* m_p;};《Singleton.cpp》#include "Singleton.h"A*A::m_p = NULL;A::A(){
Time of Update: 2018-12-05
1.把C++當成一門新的語言學習(和C沒啥關係!真的); 2.看《Thinking In C++》,不要看《C++變成死相》(C++編程思想,翻譯的非常差); 3.看《The C++ Programming Language》(這本東西有影印板的)和《Inside The C++ Object Model》 ([url]http://www.csdn.net/exper......side-cpp-object-model.htm[/url]這本東西候sir翻譯了),不要因為他們很難而
Time of Update: 2018-12-05
《TemplateMethod1.h》#include <iostream>#include <string> using namespace std;class A{public: A(){}; virtual ~A(){}; void Method();protected: virtual void b() = 0; virtual void c() = 0;};class B: public A{public: B(){};
Time of Update: 2018-12-05
工作之餘,在看資料過程中發現一個極易理解的簡單原廠模式的例子,自己親自試練一番,感覺對這個設計模式不熟悉的朋友,一看馬上就知道是什麼回事了。簡單原廠模式根據提供給它的資料,返回幾個可能類中的一個類的執行個體。通常它返的類都有一個共同的你類和共同的方法,但每個方法執行的任務不同,而且根據不同的資料進行了最佳化。簡單原廠模式是屬於建立型模式,又叫做靜態Factory 方法(Static Factory Method)模式,但不屬於23種GOF設計模式之一。下面進行一個程式碼範例:
Time of Update: 2018-12-05
mediator.h#pragma once#include <QDebug>class CMediator;class CCountry{public:virtual void setMediator(CMediator *mediator) = 0;virtual void sendMessage(const QString& message) = 0;virtual void getMessage(const QString& message) =
Time of Update: 2018-12-05
這個模式利用了回呼函數技術。command.h#pragma once#include <QDebug>class CCommand{public:virtual void execute() = 0;};class CReceiver{public:void action(){qDebug() << "action fact!";}};class ConCreateCommand : public
Time of Update: 2018-12-05
這個模式常用於Regex等interpreter.h#pragma once#include <QDebug>class CVariable;class CVarientContext{public:CVarientContext(){}virtual ~CVarientContext(){}virtual void addVarient(CVariable* key,int val) = 0;virtual void removeVarient(CVariable* key) =
Time of Update: 2018-12-05
表標頭檔 #include<sys/file.h> 定義函數 int flock(int fd,int operation); 函數說明 flock()會依參數operation所指定的方式對參數fd所指的檔案做各種鎖定或解除鎖定的動作。此函數只能鎖定整個檔案,無法鎖定檔案的某一地區。 參數 operation有下列四種情況: LOCK_SH 建立共用鎖定定。多個進程可同時對同一個檔案作共用鎖定定。 LOCK_EX
Time of Update: 2018-12-05
我們常說的迭代器iterator.h#pragma once#include <QDebug>template<class T>class CAggregate{public:CAggregate(){}virtual ~CAggregate(){}virtual int getSize() = 0;virtual T getData(int index) const = 0;virtual void setData(int index,T value) =
Time of Update: 2018-12-05
在80286以前的微處理器(CPU)組成的確16位機上,Windows作業系統(包括DOS)對於記憶體是分段使用的(分段記憶體模式,Segment Memory Mode)。運行在這些16位CPU微機上的Windows(Windows 1.0-3.1)被稱為“Win16”。從80386開始的32位CPU開始,為了相容,也採用上述分段記憶體模式,這就導致了near(short)、 far(long)指標的出現。 從Windows