Time of Update: 2018-12-04
一個類A有方法func1,有時候我們希望這個func1隻在某個特定的類B中被調用。以下是一種實現方法:template<class T>class FriendAccess...{ friend typename T; // error if write class keyword instead of typename here, but okay if typename is ignored,
Time of Update: 2018-12-04
很多地方都遇過排列組合,比如計算問題的規模,資料的大小,佔用磁碟空間多少等。原理部分借鑒網上一篇文章,道理已經說的很清楚就不重複了。(1) 全排列:全排列表示把集合中元素的所有按照一定的順序排列起來,使用P(n, n) = n!表示n個元素全排列的個數。例如:{1, 2, 3}的全排列為:123;132;213;231;312;321;共6個,即3!=3*2*1=6。這個是怎麼算出來的呢?首先取一個元素,例如取出了1,那麼就還剩下{2,
Time of Update: 2018-12-04
以下的討論都是在不用#pragma pack( num
Time of Update: 2018-12-04
昨天別人碰到的問題,晚上回來想了一下給出了一個用模板進行類型推導的解決方案。問題本身需求很清楚,就是需要寫一個Util函數,將C++裡面的那些模板(template)集合對象自動轉換成.NET裡面的泛型(Generic)集合對象,比如將vector<int>轉化成List<int>^。因為類型(Type)不定,所以用模板來進行轉化是不二的選擇。問題的痛點在於這些集合類還可以是巢狀型別,也就是說集合裡面裝的還是集合(比如將vector<vector<int>
Time of Update: 2018-12-04
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;namespace MoveNoneBoderForm{ public partial class
Time of Update: 2018-12-04
overload(重載),即函數重載:在同一個類中;函數名字相同;函數參數不同(類型不同、數量不同,兩者滿足其一即可);不以傳回值類型不同作為函數重載的條件。override(覆蓋),用於實現C++中多態:分別位於父類和子類中;子類改寫父類中的virtual方法;與父類中的函數原型相同。overwrite(重寫):與overload類似,但是範圍不同,是子類改寫父類;與override類似,但是父類中的方法不是虛函數。
Time of Update: 2018-12-04
首先必須瞭解Windows的訊息傳遞機制,當有滑鼠活動訊息時,系統發送WM_NCHITTEST 訊息給表單作為判斷訊息發生地的根據。假如你點擊的是標題列,表單收到的訊息值就是 HTCAPTION ,同樣地,若接受到的訊息是 HTCLIENT,說明使用者點擊的是客戶區,也就是滑鼠訊息發生在客戶區。當重載表單的 WndProc 方法時,可以截獲 WM_NCHITTEST 訊息並改些該訊息,當判斷滑鼠事件發生在客戶區時,改寫改訊息,發送 HTCAPTION 給表單,這樣,表單收到的訊息就時
Time of Update: 2018-12-04
早上一來看到園子裡有篇文章是說註冊快速鍵,一看用的是hook,好多的代碼,下面是我以前用的代碼:using System;using System.Runtime.InteropServices;namespace SystemHotKey{ public delegate void HotkeyEventHandler(int HotKeyID); public class Hotkey : System.Windows.Forms.IMessageFilter {
Time of Update: 2018-12-04
4種方法 對比: private void Form2_Load(object sender, EventArgs e) { string str = "這心情就像那 低熱量的雪糕,淡淡的不夠呼味道,總覺得少了什麼"; string[] a; skyvu.Tester tester = new skyvu.Tester(100000); richTextBox1.AppendText(
Time of Update: 2018-12-04
try...{ string filename;SaveFileDialog sfd = new SaveFileDialog();sfd.Title = "請選擇將匯出的EXCEL檔案存放路徑";sfd.Filter="excel文檔(*.xls)|*.xls";//sfd.OpenFile(); sfd.ShowDialog();if (sfd.FileName != "")...{if(sfd.FileName.LastIndexOf(".xls")<=0)...{sfd.Fil
Time of Update: 2018-12-04
前段時間,S2的徐*同學去了一家作核能的企業做軟體測試,在應聘的時候出了這樣一道題目。寫出string類的建構函式,拷貝建構函式,解構函式,賦值函數。 這道題目是一道相當經典的C++開發題目,是面試C++程式員時經常考的,但這次無奈徐*碰上了,為什麼呢?因為徐* 入職後作的是白盒測試。#include<iostream>using namespace std;class String{public: String(const char *str=NULL);
Time of Update: 2018-12-04
c# AttributeUsage的使用在我們開發中是十分常見的,那麼我們瞭解c# AttributeUsage的基本情況從何入手呢?那麼本文就向你詳細介紹相關的內容。 C# AttributeUsage的使用是如何的呢?首先讓我們來瞭解一下什麼是AttributeUsage類它是另外一個預定義屬性類別,AttributeUsage類的作用就是協助我們控制定製特性的使用。其實AttributeUsage類就是描述了一個定製特性如和被使用。C#
Time of Update: 2018-12-04
MessageBox("訊息內容", "傳回值 確定1",MessageBoxButtons.OK,MessageBoxIcon.Question); MessageBox("訊息內容",, "傳回值 確定1 取消2",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);MessageBox("訊息內容", "傳回值 終止3 重試4 忽略5",MessageBoxButtons.AbortRetryIgnore,
Time of Update: 2018-12-04
//SPtr.h#ifndef S_PTR_H#define S_PTR_Htemplate <typename T0, typename T1 = unsigned int> class SPtr{ template <typename T0, typename T1> friend class SPtr;public: SPtr(T0 * ptr = 0) :ptr_(ptr), use_(new T1(1)) {} SPtr(const SPtr &
Time of Update: 2018-12-04
C++的文法過於精巧,以致很多同學不能很好地理解。本文舉幾個小例子,供讀者思考。1、 inline和virtual#include <iostream>class A{public: virtual inline void func() { std::cout << "A::func" << std::endl; }};class B:public A{public: virtual inline void
Time of Update: 2018-12-04
標籤:經典 C語言 編程 垃圾 絕對能夠測試你的C語言功力的幾個問題 答案 垃圾題目 絕對能夠測試你的C語言功力的幾個問題http://www.bccn.net/Article/kfyy/cyy/jszl/200607/4181.html 解答: 垃圾題目,這種題也被作為經典?垃圾垃圾 1、strlen(str)錯誤操作,可能導致程式崩潰sizeof(str)值為102、strcpy
Time of Update: 2018-12-04
#include <stdio.h>int main(void){ FILE * file = popen("ls", "r"); int i; for(i=0; ;++i) { char buffer[1024+4]; fgets(buffer, 1024, file); if(feof(file)) break; printf("%s", buffer); } printf("%d\n", i); pclose(file); return
Time of Update: 2018-12-04
函數模板應用樣本//test.htemplate <typename M,typename N>M add(M a,N b){ return a+b;}//test.cpp#include <iostream>#include "test.h"using namespace std;void main(){ int a=15; float d=-2.8f; double b=12.5; char
Time of Update: 2018-12-04
去年參加ACM大賽遇見這個題,不知道怎樣解決,今天終於解決,原來這麼簡單,只需要用__int64 #include <iostream>using std::cout;using std::endl;int main(){ __int64 sum=0,multiply=1; for (int i=1;i!=50;++i) { multiply*=2; sum+=multiply; } cout<<sum<<endl; return
Time of Update: 2018-12-04
c++中允許函數的嵌套調用,但不允許函數的嵌套定義,例如:#include<iostream.h>int SwpInt(int *a,int *b){ int c; c=*a; *a=*b; *b=c; return a;}void main(){ int e=12; int