c++
book_zhouqingjun216
这个作者很懒,什么都没留下…
展开
-
enable_share_from_this
class CGood: public std::enable_shared_from_this{public: std::shared_ptr getPtr() { return shared_from_this(); } ~CGood() { std::cout翻译 2015-04-04 16:56:36 · 263 阅读 · 0 评论 -
enable_share_from_this
以前都没有用过enable_shared_from_this模板类,虽然经常遇到但是也没怎么去关注,今天抽时间好好学习了下enable_shared_from_this模板类,发现在使用shared_ptr模板类和enable_shared_from_this模板类时有许多陷阱的,故记录于此。什么时候该使用enable_shared_from_this模板类在看下面的例子之前,简单说下使用转载 2016-05-25 14:26:06 · 247 阅读 · 0 评论 -
enable_if
templatebool _Test, class _Ty = void> struct enable_if { // type is undefined for assumed !_Test }; templateclass _Ty> struct enable_iftrue, _Ty> { // type is _Ty for _Test typedef _Ty type;转载 2016-05-12 16:18:41 · 267 阅读 · 0 评论 -
chrono
int _tmain(int argc, _TCHAR* argv[]){ chrono::time_pointchrono::system_clock> time = std::chrono::system_clock::now(); std::this_thread::sleep_for(chrono::seconds(1)); std::chrono::system_cl原创 2016-05-15 19:20:28 · 248 阅读 · 0 评论 -
c++ UTF8转换
// estConsole.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include #include #include #include #include #include #include #include #include #in转载 2015-03-01 12:16:42 · 455 阅读 · 0 评论 -
dll 封装
class DllParser{public: DllParser() { } ~DllParser() { UnLoad(); } bool Load(const string& dllPath) { m_hMod = LoadLibraryA(dllPath.转载 2016-07-20 21:37:48 · 197 阅读 · 0 评论 -
“GCC连接静态库成功,G++连接静态库不成功”的解决方法
1.编译器“内联函数开关”引起的错误: 近来使用GCC,"Hello,World"都进行的挺顺利,但是到编译自定义类时却问题多多。程序的目的是实现C++下的字符串类,非常简单,源文件有三个: String.h //类定义的头文件 String.cxx //类实现文件 teststring.cxx //类测试转载 2016-08-04 15:57:23 · 1349 阅读 · 0 评论 -
C++ 虚函数表解析
前言C++中的虚函数的作用主要是实现了多态的机制。关于多态,简而言之就是用父类型别的指针指向其子类的实例,然后通过父类的指针调用实际子类的成员函数。这种技术可以让父类的指针有“多种形态”,这是一种泛型技术。所谓泛型技术,说白了就是试图使用不变的代码来实现可变的算法。比如:模板技术,RTTI技术,虚函数技术,要么是试图做到在编译时决议,要么试图做到运行时决议。关于虚函数的使用方法,我转载 2016-09-03 19:30:06 · 173 阅读 · 0 评论 -
C++ 对象的内存布局(上)
C++ 对象的内存布局(上) 陈皓http://blog.csdn.net/haoel 点击这里查看下篇>>>前言 07年12月,我写了一篇《C++虚函数表解析》的文章,引起了大家的兴趣。有很多朋友对我的文章留了言,有鼓励我的,有批评我的,还有很多问问题的。我在这里一并对大家的留言表示感谢。这也是我为什么再写一篇续言的原因。因为,在上一篇文章中,我用了的示例都是非转载 2016-09-03 20:44:34 · 194 阅读 · 0 评论 -
内存布局详解
图说C++对象模型:对象内存布局详解阅读目录0.前言1.何为C++对象模型?2.文章内容简介3.理解虚函数表3.1.多态与虚表3.2.使用指针访问虚表4.对象模型概述4.1.简单对象模型4.2.表格驱动模型4.3.非继承下的C++对象模型5.继承下的C++对象模型5.1.单继承5.2.多继承6.虚继承6.1.虚基类表解析6.2.简单虚转载 2016-09-03 21:36:03 · 1952 阅读 · 0 评论 -
emplace_back减少内存拷贝和移动
emplace_back能就地通过参数构造对象,不需要拷贝或者移动内存,相比push_back能更好地避免内存的拷贝与移动,使容器插入元素的性能得到进一步提升。在大多数情况下应该优先使用emplace_back来代替push_back。所有的标准库容器(array除外,因为它的长度不可改变,不能插入元素)都增加了类似的方法:emplace、emplace_hint、emplace_front、em转载 2016-08-13 16:48:32 · 496 阅读 · 0 评论 -
调用函数不同参数以及返回值
templateclass CTC{public: CTC(std::function f) { fu = f; } template void Exec(Args&&...args) { fu(std::forward (args)...); }private:原创 2016-11-03 12:07:31 · 332 阅读 · 0 评论 -
可以传入多参的观察者模式
class NoCopy{protected: NoCopy() = default; NoCopy(const NoCopy& n) = delete; NoCopy&operator=(const NoCopy&) = delete; ~NoCopy() = default;};templateclass Event : publ转载 2016-11-03 12:32:59 · 318 阅读 · 0 评论 -
qt5 有中文使用vs编译时失败,以及中文显示乱码
1、修改编译失败问题修改成红色圈住内容2、中文乱码问题在有中文的那个文件头加入以下内容#pragma execution_character_set("utf-8")转载 2016-10-29 17:22:42 · 432 阅读 · 0 评论 -
c++ 变长模板
templatevoid f(const T& t){ cout }templatevoid f(const T& t, const Arg&... arg){ cout f(arg...); }int main(){ f(10, 20, 30); system("pause");原创 2015-04-01 20:37:21 · 324 阅读 · 0 评论 -
log4cpp
#include "log4cpp/Category.hh"#include "log4cpp/OstreamAppender.hh"#include "log4cpp/BasicLayout.hh"#include "log4cpp/Priority.hh"#include "log4cpp/PatternLayout.hh"#include "log4cpp/SimpleL原创 2015-10-06 21:35:13 · 344 阅读 · 0 评论 -
boost log
#include #include #include #include #include #include #include #include #include namespace logging = boost::log;namespace sinks = boost::log::sinks;namespace a转载 2015-10-06 22:33:57 · 248 阅读 · 0 评论 -
模板处理数组
templatevoid Test(T (&arr)[N]){ for (int i = 0; i cout }int _tmain(int argc, _TCHAR* argv[]){ double arr[]{ 1,2,4,4,5 }; Test(arr);}转载 2015-04-05 11:24:44 · 265 阅读 · 0 评论 -
boost asio异步简单测试
#include "stdafx.h"#include #include #include #include #include #include using namespace boost::asio;using namespace std;using ip::tcp;class TestServer{public: TestSer原创 2015-04-05 12:49:26 · 305 阅读 · 0 评论 -
测试简单的asio异步服务过程
#include "stdafx.h"#include #include #include #include #include #include #include #include #include using namespace std;using namespace boost;using boost::asio::ip::tcp;转载 2015-04-06 10:52:35 · 293 阅读 · 0 评论 -
使用functional
#include using namespace std;class CTT{public: int Mul(int a, int b) { return a * b; } int Add(int a, int b) { return a + b; }};in原创 2015-04-06 20:55:14 · 436 阅读 · 0 评论 -
bind使用
int add(int a, int b){ return a + b;}int sub(int a, int b){ return a - b;}templateauto Test(const T&& t, const V& v1, const V& v2)->decltype(v1+v2){ auto vv = bind(t原创 2015-04-19 18:17:36 · 376 阅读 · 0 评论 -
使用system_error
#include using namespace std;class AppError : public std::error_category{public: AppError(){} const char *name() const _NOEXCEPT { return "AppError"; }原创 2015-04-07 21:50:21 · 685 阅读 · 0 评论 -
测试forward
struct X {}; void inner(const X&) {cout "inner(const X&)" void inner(X&&) {cout "inner(X&&)" templatetypename T> void outer(T&& t) {inner(forward(t));} int main() { X a; outer(a);转载 2015-04-13 11:21:20 · 289 阅读 · 0 评论 -
模板全特化
struct CTemp{ const char* nc; const wchar_t* wc; template inline const _Elem* Get()const; };templateinline const char* CTemp::Get()const{ return nc;}t原创 2015-04-20 10:33:00 · 306 阅读 · 0 评论 -
c++ 并发处理
#include #include #include #include #include #include #include #include using namespace concurrency;using namespace std;// Calls the provided work function and returns the numb转载 2015-04-21 14:21:57 · 283 阅读 · 0 评论 -
读写ini
#include #include #include #ifndef _UNICODE #define tptree boost::property_tree::ptree #else #define tptree boost::property_tree::wptree #endif #define BOOST_ALL_DYN_原创 2015-04-30 22:45:00 · 267 阅读 · 0 评论 -
c++ bind functional
#include #include #include #include #include "Test.h"using namespace std;int test(int a, int b){ cout return 10;}int main(){ //CTest test; //CTest *t原创 2015-06-08 20:40:33 · 332 阅读 · 0 评论 -
enable_if
1 导言 使用 enable_if 系列模板可以控制一个函数模板或类模板偏特化是否包含在基于模板参数属性的一系列匹配函数或偏特化中。比如,我们可以定义一个只对某些类型(通过特征类[traits class]定义)有效——当然也只匹配这些类型——的函数模板。enable_if 也可以对类模板偏特化实现同样的效果。enable_if 的应用在 [1] 和 [2] 中有详细的介绍。转载 2015-06-09 10:48:33 · 330 阅读 · 0 评论 -
default,delete
class CTestEx{public: CTestEx() = default; //可以使用默认构造 CTestEx(const std::string& str):mstr(str){} std::string what() { return mstr; } void* operator new(size_t) = delete;原创 2015-07-28 09:17:51 · 229 阅读 · 0 评论 -
sleep_until
using std::chrono::system_clock; std::time_t tt = system_clock::to_time_t(system_clock::now()); struct std::tm * ptm = std::localtime(&tt); std::cout std::cout ++ptm转载 2015-08-23 21:38:01 · 288 阅读 · 0 评论 -
MainWindow 设置layout问题
MainWindow::MainWindow() { // Set layout QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(myWidget1); layout->addWidget(myWidget2); // Set layout in转载 2016-10-29 22:06:05 · 890 阅读 · 0 评论