设为首页 加入收藏

TOP

引用内部函数绑定机制,R转义字符,C++引用,别名,模板元,宏,断言,C++多线程,C++智能指针(二)
2015-07-20 17:53:44 来源: 作者: 【 】 浏览:7
Tags:引用 内部 函数 绑定 机制 转义 字符 别名 模板 断言 线程 智能 指针

#include

#include

#include

#include

usingnamespacestd;

usingnamespacestd::this_thread;

voidmsg()

{

MessageBoxA(0,"12345","678910",0);

}

voidmsgA(intnum)

{

std::cout << get_id() <<" num = " <

}

voidmain()

{

vector threads;

for (inti = 0;i < 10;i++)

{

threads.push_back(newthread(msg));//创建线程

}

for (autoth :threads)

{

th->join();

}

std::cin.get();

}

\

10.线程间通信

#include

#include

#include

#include

usingnamespacestd;

usingnamespacestd::this_thread;

voidmsgA(intnum)

{

std::cout << get_id() <<" num = " <

}

voidmain()

{

vector threads;

for (inti = 0;i < 10;i++)

{

//其中后面的msgA为函数名,i为为函数传递的参数

threads.push_back(newthread(msgA,i));//创建线程

}

for (autoth :threads)

{

th->join();

}

std::cin.get();

}

程序运行结果如下:

\

11.C++中的智能指针

#include

#include //内存

voidmain()

{

for (inti = 0;i < 10000000;i++)

{

//新型指针,新型的数组

std::unique_ptr pdb(newdouble);

//通过指针执行来自动释放内存

//double *p = new double;

}

std::cin.get();

}

12.另外一种智能指针

#include

voidmain()

{

//auto_prt

for (inti = 0;i < 10000000;i++)

{

double *p = newdouble;//为指针分配内存

std::auto_ptr autop(p);

//创建智能指针管理指针p指向内存

//智能指针

//delete p;

}

std::cin.get();

}

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇从汇编来看i++与++i 下一篇C++中的数组array和vector,lambd..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: