2013年1月8日

TerminateThread 不要使用的证据

摘要: 听过无数次不要TerminateThread,只是工作中常用,貌似也没有什么问题。今天在高强度测试中发现了一个不可原谅的错误。参看下面的例子DWORD __stdcall mythread(void* ){ while( true ) { char* p = new char[1024]; delete p; }}int _tmain(int argc, _TCHAR* argv[]){ HANDLE h = CreateThread(NULL, 0, mythread, NULL, 0, NULL); Sleep(1000); TerminateThread(h, 0); h = NULL; 阅读全文

posted @ 2013-01-08 17:40 code.life 阅读(171) 评论(0) 推荐(0)

关于Main()函数的小技巧

摘要: 话说,有这样一道笔试题:#include "stdio.h"void print(){*}void main(){}要求在*部分写代码使整个程序运行后输出“hello world”,有些人说,这还不简单啊,于是写出这样的代码:01.#include "stdio.h" 02.void print()... 阅读全文

posted @ 2013-01-08 17:37 code.life 阅读(146) 评论(0) 推荐(0)

类型转换(Type casting)

摘要: 1 //首先简单介绍下C++默默为我们生成和调用的函数 2 class Empty {}; 3 //如果你写上面的code, C++编译器会为你生成下面的code 4 class Empty{ 5 public: 6 Empty() {...} ... 阅读全文

posted @ 2013-01-08 17:11 code.life 阅读(350) 评论(0) 推荐(0)

模板实参推断(Template argument deduction)

摘要: 函数模板(Function template) 和 类模板(Class template)1.函数模板 类型实参的类型转换受限,一般而论,不会转换实参以匹配已有的实例化,相反,会产生新的实例。除了产生新的实例化之外,编译器只会执行两种转换。View Code 1 template <typename T> T fobj(T, T); //arguments are copied 2 3 template <typename T> 4 T fref(const T&, const T&); //reference arguments 5 6 string 阅读全文

posted @ 2013-01-08 11:34 code.life 阅读(226) 评论(0) 推荐(0)

导航