经验:避免返回handles(包括 references、指针、迭代器)指向对象内部。遵守这个条款可增加封装性,
帮助 const 成员函数的行为像个 const,并将发生“虚吊号码牌”(dangling handles)的可能性降至最低。
示例:
class Point{
public:
Point(int x, int y);
//...
void setX(int newVal);
void setY(int newVal);
//...
};
struct RectData{
Point...
分类:
编程语言 时间:
2014-07-10 22:56:05
阅读次数:
230
经验:当std::swap对你的类型效率不高时,提供一个swap成员函数,并确定这个函数不抛出异常
示例:
stl里的swap算法
namespace std{
template
void swap(T &a, T &b){
T temp(a);
a = b;
b = temp;
}
}
//“pimpl手法”(pointer to implementation) --> 文件间的编译依存度
class WidgetImpl{
public:
//...
pr...
分类:
编程语言 时间:
2014-07-10 19:35:50
阅读次数:
240
var aa: array [0..5] of Char; bb:Pointer; cc:string; dd:PChar;procedure TForm1.Button1Click(Sender: TObject);begindd:='abcdef'; //以下是pchar内容转数组FillCha...
分类:
其他好文 时间:
2014-07-06 21:56:57
阅读次数:
264
BOOL CopyFile( LPCTSTR lpExistingFileName, // pointer to name of an existing file LPCTSTR lpNewFileName, // pointer to filename to copy to BOOL bFailI...
分类:
编程语言 时间:
2014-07-05 17:16:57
阅读次数:
275
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
分类:
其他好文 时间:
2014-07-03 23:46:37
阅读次数:
389
??
垃圾回收用来实现内存的自动管理(automatic management),区别于人工管理(manual management)。人工管理内存容易出现的问题:
1)悬垂指针,dangling pointer
2)重复回收,Double free
3)内存泄露,memory leak
历史
垃圾回收的概念及技术由John McCarthy于1959年发明,应用于List...
分类:
其他好文 时间:
2014-07-03 16:34:03
阅读次数:
194
1:函数名为指针
首先,在C语言中函数是一种function-to-pointer的方式,即对于一个函数,会将其自动转换成指针的类型.如:
1 #include
2
3 void fun()
4 {
5 }
6
7 int main()
8 {
9 printf("%p %p %p\n", &fun, fun, *fun);
10 return 0...
分类:
编程语言 时间:
2014-07-03 13:30:17
阅读次数:
363
#define BTS_SAFE_DELETE(POINTER) \do { if (POINTER != 0) { BTS_DELETE(POINTER); POINTER = 0;} \} while (0)注意:宏定义必须在一行,否则报错!\ 表示本行未结束, 没有该连接符时,直接换行编译器会...
分类:
其他好文 时间:
2014-07-03 10:25:27
阅读次数:
186
1. Error: Dangling meta character '*' near index 0对字符串使用split()方法截取 * ? + / | 等字符的时候会报以下异常 Dangling meta character '?' near index 0 ?+、*、|、\等符号在正则表达示中...
分类:
编程语言 时间:
2014-07-03 07:13:36
阅读次数:
222
VC中常见编译错误(转载看看)1)disable#pragma warning (disable: 4311 4312) //指针类型强制转化,大小不完全匹配warning C4311: ''type cast'' : pointer truncation from ''TriNode *const...
分类:
其他好文 时间:
2014-07-03 07:01:57
阅读次数:
214