Time of Update: 2018-12-06
看到這篇文章:http://tech.pro/tutorial/1155/obtaining-method-caller-information-in-c 感覺挺有用處,就節選重點翻譯下。 在日誌組件中,我們可能需要記錄方法調用資訊。.NET 4.5/Visual Studio 2012提供了很方便地支援這一功能。 要記錄的方法調用資訊包括:方法成員名稱源檔案路徑行號
Time of Update: 2018-12-06
class singleton{ public: static singleton* instance(); //聲明一個靜態成員函數 protect: singleton(); private: static singleton* _instance; //聲明一個靜態成員變數};singleton* singleton::_instance = 0;singleton* singleton::instance(){ if( _instance == 0 )
Time of Update: 2018-12-06
位操作符: 將其整型運算元視為二進位位的集合,為每一位提供檢驗和設定的功能。~
Time of Update: 2018-12-06
已知strcpy的函數原型:char *strcpy(char *strDest, const char *strSrc),其中strDest 是目的字串,strSrc 是源字串。不調用C++/C 的字串庫函數,請編寫函數 strcpy。 1 #include <cassert> 2 3 char* strcpy(char* strDest, const char* strSrc) 4 { 5 assert(strDest && strSrc); //
Time of Update: 2018-12-06
// Singleton.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <iostream>using namespace std;class Singleton{public: Singleton(){} virtual ~Singleton(){} static Singleton* GetInstancePtr() { if(NULL==m_pStatic) { m_pStatic=new Singleton();
Time of Update: 2018-12-06
// Compisite.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <iostream>#include <list>#include <algorithm>using namespace std; class Componet{public: Componet() { } virtual ~Componet() { } virtual void Operation()=0; virtual void
Time of Update: 2018-12-06
// Memento.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <iostream>#include <string> using namespace std; typedef string STATE; class Memento;class Originator{public: Originator(){} Originator(const STATE&
Time of Update: 2018-12-06
// Command.cpp : 定義控制台應用程式的進入點。// /*該實現為最簡單方式。 */#include "stdafx.h"#include <iostream>using namespace std;class Command{public : Command() { } virtual~ Command() { } virtual void Execute()=0;};class Receiver{public: Receiver() { } virtual
Time of Update: 2018-12-06
// Facade.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <iostream>using namespace std;class ServiceClass{public: ServiceClass() { cout<<"Construction of ServiceClas"<<endl; } virtual ~ServiceClass() { } void
Time of Update: 2018-12-06
// Template Method.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <iostream>using namespace std;class AbstractClass{public: AbstractClass(){} virtual ~AbstractClass(){} // 這個函數中定義了演算法的輪廓 void TemplateMethod() { PrimitiveOperation1();
Time of Update: 2018-12-06
// Flyweight.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include <iostream>#include <list>#include <string>using namespace std;typedef string STATE;class Flyweight{public: STATE GetIntrinsicState() { return m_state; } virtual void
Time of Update: 2018-12-06
重新定義一個繼承而來的non-virtual函數永遠都是錯誤的,本條款的討論限制在“帶有預設參數的virtual函數”。virtual函數是動態綁定的,而預設參數卻是靜態繫結。對象的所謂靜態類型,是它在程式中被聲明時所採用的類型。 #include "StdAfx.h"#include <iostream>using namespace std; class Shape { public: enumShapeColor {Red, Green, Blue};
Time of Update: 2018-12-06
轉載網址:http://www.cppblog.com/smagle/archive/2010/05/14/115286.aspx在揭開typeid神秘面紗之前,我們先來瞭解一下RTTI(Run-Time Type
Time of Update: 2018-12-06
(1)首先通過一個例子看(int)和(int&)的區別:float a = 1.0f;cout << (int)a << endl;cout << (int&)a << endl;cout << boolalpha << ( (int)a == (int&)a ) << endl; // boolalpha 用符號形式表示真假float b = 0.0f;cout <<
Time of Update: 2018-12-06
1,函數的基本知識 C++對於傳回值的類型有一定的限制:不能是數組,但可以使其他任何類型,甚至可以使結構和對象。 有趣的是,雖然數組不可以作為返回對象,但是數組可以作為結構或對象組成部分來返回。2,函數參數和按值傳遞 cin.get();//讀取所有輸入的字元,包括空格和分行符號。 cin>> ;//跳過空格和分行符號讀取。3,函數和數組 int arr[32]; int sum_arr(int arr[],
Time of Update: 2018-12-06
string 是C++中的字串。 字串對象是一種特殊類型的容器,專門設計來操作的字元序列。 不像傳統的c-strings,只是在數組中的一個字元序列,我們稱之為字元數組,而C + +字串對象屬於一個類,這個類有很多內建的特點,在操作方式,更直觀,另外還有很多有用的成員函數。 string 的定義為:typedef basic_string<char> string;成員函數(Member functions) (constructor) 構建字串對象
Time of Update: 2018-12-06
C++ is a Huuuuuge Language.The Path towards Expertise would be:Understanding C++ - Step 0You have got to read The C++ Programming Language by Stroustrup, no way you can escape this. http://www.amazon.com/The-Progra... Understanding Histrory of C++
Time of Update: 2018-12-06
scanf( )函數和gets( )函數都可用於輸入字串,但在功能上有區別。若想從鍵盤上輸入字串"hi hello",則應該使用__gets__函數。gets可以接收空格;而scanf遇到空格、斷行符號和Tab鍵都會認為輸入結束,所有它不能接收空格。char string[15]; gets(string); /*遇到斷行符號認為輸入結束*/scanf("%s",string);
Time of Update: 2018-12-06
//擷取啟動了應用程式的可執行檔的路徑,不包括可執行檔的名稱。 string str5=Application.StartupPath;//可獲得當前執行的exe的檔案名稱。 string str1 =Process.GetCurrentProcess().MainModule.FileName;//擷取和設定目前的目錄(即該進程從中啟動的目錄)的完全限定路徑。 備忘
Time of Update: 2018-12-06
這個函數執行得出的結果不正確:---------------------------------------------------------------------------------------------------------------------------- public IList<int> getAmountOfFastnessWindValueInVillage(string value, string VillageCode)