随笔分类 -  cpp

wxwidget自定义消息处理步骤
摘要:fromhttp://www.cppblog.com/kenlistian/archive/2009/02/06/73096.html略有修改wxwidget自定义消息处理步骤自定义消息处理(不知道在wxpython,wxruby如何自定义类型消息?最好装个wxpython,在其demo现场编写现场查看结果)步骤如下:1.在宏里处理如下:a.BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_MYCOMMAND, xxxx)END_DECLARE_EVENT_TYPES() xxxx 为自定义数字,不过翻到wxwidget内部,其宏定... 阅读全文

posted @ 2014-02-12 15:32 Orz.. 阅读(688) 评论(0) 推荐(0)

c++的检测的确比C++更严格
摘要:见下面代码#include #include #include enum guess { paper, scissors, rock,};int main(void){ enum guess pc = 2; enum guess man; //int pc = 2; //int man; int tmp; tmp = 1; man = tmp % 3; int ret = abs((man - pc) % 3); printf("%d\n", (man-pc)); printf("man = %d, pc = %d,... 阅读全文

posted @ 2014-02-02 12:06 Orz.. 阅读(457) 评论(0) 推荐(0)

位移时小心一下运算符的优先级
摘要:__int64 index = (pDevNode->nParentId nDeviceVid;与 __int64 index = pDevNode->nParentId nDeviceVid;是不同的 阅读全文

posted @ 2013-10-18 14:48 Orz.. 阅读(244) 评论(0) 推荐(0)

C++实现Creational - Singleton模式
摘要:http://patmusing.blog.163.com/blog/static/135834960201002322226231/1. C++实现Creational - Singleton模式2010-01-23 02:22:26|分类:Pattern|标签:c++设计模式|字号订阅Singleton设计模式经常被大家谈及,很多人认为该模式很简单。的确,从纯粹的设计模式的角度来看,它并不复杂,但是从实现的角度来看,其实非常不简单,尤其是用C++去实现它的时候。一、Java版本的Singleton模式实现我们不妨先看看在Java中实现Singleton模式的典型代码:// Singleto 阅读全文

posted @ 2013-04-03 22:28 Orz.. 阅读(217) 评论(0) 推荐(0)

很好的boost学习资料
摘要:fromhttp://www.cppblog.com/true/archive/2010/08/20/124057.html这是中文版:http://zh.highscore.de/cpp/boost/http://code.google.com/p/boost-doc-zh/ 阅读全文

posted @ 2013-04-03 12:47 Orz.. 阅读(757) 评论(0) 推荐(0)

boost 程序库完全开发_ch4_utility
摘要:#include <iostream>#include <boost/utility.hpp>//#include <boost/noncopyable.hpp>//#include <boost/assign.hpp>#include <boost/swap.hpp>#include <algorithm>using namespace std;using namespace boost;#if 0//class X:noncopyableclass X{ X(const X& ); const X& o 阅读全文

posted @ 2013-03-27 11:13 Orz.. 阅读(246) 评论(0) 推荐(0)

boost 程序库完全开发指南_ch3_memory_manager
摘要:ch3的代码块好像还真的不用编译,只需要把代码嵌入即可#include <iostream>#include <memory>#include <vector>using namespace std;#include <boost/smart_ptr.hpp> #include <boost/make_shared.hpp>#include <boost/enable_shared_from_this.hpp>using namespace boost; #if 0struct posix_file //一个示范性质的文件 阅读全文

posted @ 2013-03-26 20:18 Orz.. 阅读(262) 评论(0) 推荐(0)

auto_ptr的不足
摘要:一开始还发现这货挺方便的.后来才发现还是不行,多引用时,就会重复删除了#include <iostream>#include <memory>using namespace std;void func(const auto_ptr<int>& pInt){ cout << *pInt<<endl;}class X{public: X(){cout <<"construct"<<endl;} ~ X(){cout <<"destructor"<&l 阅读全文

posted @ 2013-03-24 23:47 Orz.. 阅读(214) 评论(0) 推荐(0)

boost 程序库完全开发指南_date_time
摘要:下面是看boost 程序库完全开发指南时,date_time(chapter2)时所敲下的代码片断....,不保证其正确性,仅作为一个记录....#include"stdafx.h"#include <vector>#include <string>#include <fstream>#include <windows.h>#include <boost/progress.hpp>#include <iostream>#include <algorithm>using namespace s 阅读全文

posted @ 2013-03-24 22:19 Orz.. 阅读(749) 评论(0) 推荐(0)

boost test的测试环境
摘要:试了一下boost 的测试框架,,发现还是可用的正常解开后,如果只是调用BOOST_AUTO_TEST_SUITE(test1)BOOST_AUTO_TEST_CASE(t_test2){ BOOST_CHECK_EQUAL(my_add(2,3), 5);}BOOST_AUTO_TEST_SUITE_END()这几部分好像还真的可以直接内嵌代码中去我把boost 的代码库的src 放进了f:\boost/*t1.cpp*/#define BOOST_TEST_MAIN #define BOOST_TEST_INCLUDED#include <boost/test/included/un 阅读全文

posted @ 2013-03-24 14:12 Orz.. 阅读(276) 评论(0) 推荐(0)

C++ 友元函数
摘要:#include <iostream>using namespace std;class Y;class X{ int _foo;public: X(int n):_foo(n){} void foobar(Y& y);};class Y{ friend class X; int _bar;public: Y(int n):_bar(n){}};void X::foobar(Y& y){ cout << y._bar << endl;} int main() { X x(3); Y y(4); x.foobar(y); return 0; } 阅读全文

posted @ 2013-03-24 08:56 Orz.. 阅读(140) 评论(0) 推荐(0)

C++重载的时候会优先匹配非模块函数
摘要:发现当重载函数足够多的时候,出现可以符合非模块函数,及模块函数都可匹配的时候,GCC好像会优先匹配非模块函数.见下面代码#include <iostream>#include <vector>#include <string>#include <limits>using namespace std;int max(const int n1, const int n2){ return n1 > n2 ? n1 : n2;}float max( const float f1, const float f2){ return f1 > f 阅读全文

posted @ 2012-12-15 19:19 Orz.. 阅读(536) 评论(0) 推荐(0)

求string数组完数的个数
摘要:见下面的代码片断,string str_array[] = {"boog", "gogod", "zero", "loe", "abcdasdfas", "asfdksdljjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj 阅读全文

posted @ 2012-12-15 17:30 Orz.. 阅读(444) 评论(0) 推荐(0)

继承一个虚类的时候要小心是,并使其实例化时.必须使其全实重写了纯虚的方法...类定义的位置
摘要:http://stackoverflow.com/questions/7352706/cannot-allocate-an-object-of-abstract-type-errorIn C++ a class with at least onepure virtual functionis calledAbstract classand you cannot create objects of that class, You can only have pointers or references to it.If you are deriving from an Abstract clas 阅读全文

posted @ 2012-10-30 00:41 Orz.. 阅读(545) 评论(0) 推荐(0)

那个蛋痛的list的remove_if中用到的对像函数
摘要:题目够长的....其实有时.要小用list来作一些过滤..我知道list的随机查找不太好...可是有时写好了,,性能上也没有太多要求..就....所以我就直接remove_if...先在http://www.cplusplus.com/reference/stl/list/remove_if/找了个示例代码如下// list::remove_if#include <iostream>#include <list>using namespace std;// a predicate implemented as a function:bool single_digit ( 阅读全文

posted @ 2012-10-27 23:53 Orz.. 阅读(615) 评论(0) 推荐(0)

0xXXXX与short的比较.要小心
摘要:main.cpp: In function ‘bool foo()’:main.cpp:6: warning: comparison is always false due to limited range of data type 1 #include <stdio.h> 2 bool foo() 3 { ... 阅读全文

posted @ 2012-09-07 15:24 Orz.. 阅读(609) 评论(0) 推荐(0)

c++ stl 的string 的size() legth()区别
摘要:最近在查一个bug的时候看到这个说法,看了一下.有几种说法也有人说出一系的解释VC.net 7.0中:size_type length() const{ // return length of sequencereturn (_Mysize);}size_type size() const{ // return length of sequencereturn (_Mysize);}GCC 3.3.3中:size_typesize() const { return _M_rep()-> _M_length; }size_typelength() co... 阅读全文

posted @ 2012-08-14 16:27 Orz.. 阅读(497) 评论(1) 推荐(1)

又一个低级错误.....new 了两次....
摘要:... pthread_t id = pthread_self(); //DBMgr* pdb = NULL; DBMgr* pdb; if (conn_map_.find_by_key(id, &pdb)) { new pdb = new DBMgr(); pdb->Init(ip_, port_,... 阅读全文

posted @ 2012-08-13 15:22 Orz.. 阅读(218) 评论(0) 推荐(0)

map用索引作下标之后,再插值时报错.
摘要:DBMgr* ConnPool::GetConn() { pthread_t id = pthread_self(); //unsigned long id = pthread_self(); ... 阅读全文

posted @ 2012-08-10 17:10 Orz.. 阅读(450) 评论(0) 推荐(0)

用NULL来构造string会出问题
摘要:最近某应用跑压力测试的时候出现了下面的错[2012-07-31 22:33:59:271046, db_mgr.cpp:GetDeviceInfo:1129, DBG , 0xb35f4b90]: select object_id, object_name, object_type_id, class_type_id, device_type_id from m_object where object_id = 225663102terminate called after throwing an instance of 'std::logic_error' what(): b 阅读全文

posted @ 2012-07-31 23:18 Orz.. 阅读(2620) 评论(0) 推荐(0)

导航