Time of Update: 2018-07-18
通過default建構函式出一個對象再對他賦值比直接在構造時指定賦值 差。 比如 string str("honey~");和 string str; str="honey~";效率就不一樣。 接下來講迴圈時的初始化, /* class A; A a; for(int i=0;i<n;i++) //1次構造,1次析構,n次賦值。 {a=**;} */ class A;
Time of Update: 2018-07-18
namespace std { template<class T> void swap(T&a,T&b) { T temp(a); a=b; b=temp; } } //T支援copying函數即可。 //pimpl手法:以指標指向一個對象,內含真正資料。 //在namespace std中只能全特化,不能偏特化, //如 namspace std { template<> void swap<A>(A&a,A&b) { ...
Time of Update: 2018-07-18
TMP 模板元編程 0.explicit建構函式比non-explicit建構函式好。 1.可以用const 來代替#define 定義一個常量。 #define沒有範圍,也沒有封裝性。 class A { private: static const int NUM=5; //當常量為static且為整數類型,則可將不需定義式。 }; const int A::NUM; //NUM的定義。在聲明式中已經獲初值,所以無需在定義式給初值。
Time of Update: 2018-07-18
class A { public: A(); ~A(); A& operator=(const A& a); //複製的是non-static成員 A(const A&a); }; 當自己聲明了一個建構函式,則default建構函式將不會自動產生。C++不允許reference改指向不同對象。如果想要避免對象賦值,則可將賦值建構函式在private中聲明。 接下來要討論的是虛解構函式問題。 class
Time of Update: 2018-07-18
資源:有用有還。 資源:記憶體,檔案描述器,互斥鎖,圖形介面中的字形和筆刷,資料庫連接,socket class Investment {}; Investment* createInvestment(); void f() { Investment* pInv = createInvestment(); ... delete pInv; //如果在...中有return或拋出異常就無法刪除指標。 } //由此得出必須要自動刪除而不是手動刪除,因此要建立在對象之中管理資源。
Time of Update: 2018-07-18
原題略。 答案的問題在於 當一開始數組的第一個元素為0時,他為偶數,刪除它後,迭代器指向第一個元素1 , 錯誤在於下一句,--lit 使得迭代器指向begin的前一個,超出了範圍,所以導致運行錯誤。 必須要瞭解for語句的實現,則可以解決這個問題。 #include<vector> #include<iostream> #include<list> using namespace std;
Time of Update: 2018-07-18
先看一個網上經典的例子。 #include "stdafx.h" #include <cstdlib> #include <stdlib.h> #include <boost/regex.hpp> #include <string> #include <iostream> using namespace std; using namespace boost; regex
Time of Update: 2018-07-18
一、引言 1. 問題的引入
Time of Update: 2018-07-18
由於項目中調用了動態庫,這些動態庫放在C:\Windows\System32下面,但是當部署到了64位的機器上可能就有問題了,最近這個問題就糾結了半天,在本機32為系統上測試動態調用ddl成功了,部署到64位Window Server2008上面也沒問題,可是為什麼到了64位的WIN7系統上出了問題呢。
Time of Update: 2018-07-18
//C++中的DLL函數原型為 //extern "C" __declspec(dllexport) bool 方法名一(const char* 變數名1, unsigned char* 變數名2) //extern "C" __declspec(dllexport) bool 方法名二(const unsigned char* 變數名1, char* 變數名2)
Time of Update: 2018-07-18
From: http://my.oschina.net/chenyoca/blog/226455 摘要 出現這個編譯錯誤的原因在g++ gcc 版本不夠高。 目錄[-] 添加源(Ubuntu) 安裝4.8版本 查看本地安裝版本 切換版本 再次查看g++版本 出現這個編譯錯誤的原因在g++ gcc 版本不夠高。
Time of Update: 2018-07-18
#include<unistd.h> #include<sys/types.h> #include<sys/wait.h> #include<stdio.h> #include<stdlib.h> #include<fcntl.h> #include<limits.h> #define BUFSZ 150 void err_quit(char *msg) { perror(msg);
Time of Update: 2018-07-18
private bool FindNode(TreeNode Node) ...
Time of Update: 2018-07-18
C#中的逸出字元跟C/C++的定義一致。有以下常用轉移字元: 逸出字元 字元名稱 \' 單引號 \" 雙引號 \\ 反斜線 \0 Null 字元 \a
Time of Update: 2018-07-18
最近需要做協助文檔,所以在網上查了一下,這裡把一些有用的資料摘錄一下。 1. 首先這篇文章是比較詳細的一個介紹: Open Help file on F1 function key press in windows application This article explains how to open help file on F1
Time of Update: 2018-07-18
using System;using System.Data;using System.Windows.Forms; namespace ClothLib.DataAccess{ /// <summary> /// paging 的摘要說明。 /// </summary> public class paging { int PageCount; int
Time of Update: 2018-07-18
代碼如下: #include <iostream>#include <vector>using namespace std;int main(){ cout << "c++ stl vector and iterator test!" << endl; cout << "increase number" << endl; vector<int>
Time of Update: 2018-07-18
STL 描述: C++標準模組庫是一個提供了公用編程資料結構和函數的模板類集合,如雙串連表(list),配對數組(map),可擴充數組(vector),大串的儲存操作(rope)等。STL庫可以從http://www.sgi.com/tech/stl/ 擷取。 STL可以分為以下幾類: 容器類: 順序容器: vector:動態陣列變數,結構體或對象。可以插入在末尾插入資料,支援快速隨機訪問。 deque:
Time of Update: 2018-07-18
參考資料:C++ primer 5th edition (1) 3.5.4 "C-Style Character Strings" (2) 3.5.1 "Character Arrays Are Special" (3) 3.2.1 "Defining and Initializing 'string's " (4) 2.1.3 "Character and Character String Literals&
Time of Update: 2018-07-18
索引:[LeetCode] Leetcode 題解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 039. Combination Sum (Medium) 連結: 題目:https://leetcode.com/problems/combination-sum/ 代碼(github):https://github.com/illuz/leetcode 題意: