Hello Coney
2017-09-29T03:05:22.915Z
http://coney.github.io/
Coney Wu
Hexo
GMOCK下对const函数重载的处理
http://coney.github.io/2015/09/gmock-with-const-function/
2015-09-11T04:32:00.000Z
2017-09-29T03:05:22.915Z
<p>在C++中我们可能会遇到函数名, 函数签名, 返回值都相同的重载, 唯一的区别是const和non-const, 例如:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">SomeClass</span> {</span></div><div class="line"><span class="keyword">public</span>:</div><div class="line"> <span class="keyword">virtual</span> ~SomeClass() <span class="keyword">throw</span>() {}</div><div class="line"> <span class="keyword">virtual</span> <span class="keyword">int</span> get() = <span class="number">0</span>;</div><div class="line"> <span class="function"><span class="keyword">virtual</span> <span class="keyword">int</span> <span class="title">get</span><span class="params">()</span> <span class="keyword">const</span> </span>= <span class="number">0</span>;</div><div class="line">};</div></pre></td></tr></table></figure>
<p>这种类我们在使用时编译器会根据我们的传入对象是否带有const属性自动调用对应的版本, 但是通过GMOCK的编写Mock调用时, 很多人对如何设置const函数的EXPECT_ALL和调用产生了疑问.<br>其实处理方式也比较简单, 在使用EXPECT_CALL或者调用mock对象的方法时, 我们可以显示通过const_cast将mock对象的转为const版本.<br>例如对于上面的类, 我们可以这么去写Mock, 设置期望和调用:</p>
handle ambiguous overloaded functions in gmock
http://coney.github.io/2015/08/handle-ambiguous-overloaded-functions-in-gmock/
2015-08-21T07:44:24.000Z
2017-10-01T15:19:11.674Z
<p>在声明的接口中, 可能会存在返回值及函数参数个数一直的情况, 例如下面<code>Inf::f()</code>方法:</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><div
移除HTTP Proxy的NTLM认证
http://coney.github.io/2015/08/setup-cntlm-for-ntlm-http-proxy/
2015-08-06T16:04:58.000Z
2017-10-01T15:19:52.203Z
<p>某些企业内网处于安全考虑, 封堵了互联网访问, 外网出口仅保留一个HTTP Proxy, 在国内不少企业会架设AD并使用ISA作为代理服务器及防火墙.</p>
<p>通过ISA支持的NTLM认证能够比较方便的实现Windows端的SSO, 但是这种明显Windows风的认证方式却有很多HTTP客户端不支持.</p>
<p>例如在某客户现场使用npm通过代理安装包时, npm无法通过NTLM认证导致安装失败. 此时我们可以选择CNTLM将代理转化为不需要认证的HTTP代理.</p>
<p>首先从<a href="http://cntlm.sourceforge.net/" target="_blank" rel="external">CNTLM</a>官方网站下载最新版本的CNTLM程序:</p>
<p><a href="http://sourceforge.net/projects/cntlm/files/" target="_blank" rel="external">http://sourceforge.net/projects/cntlm/files/</a></p>
C++ 源码阅读项目推荐
http://coney.github.io/2015/08/cpp-projects-for-source-reading/
2015-08-06T02:25:47.000Z
2017-09-29T03:13:25.634Z
<h3 id="Chromium"><a href="#Chromium" class="headerlink" title="Chromium"></a>Chromium</h3><ul>
<li>流行浏览器的Chrome的开发版本</li>
<li>源码符合Google C++ 编程风格规范<a href="http://google.github.io/styleguide/cppguide.html" target="_blank" rel="external">Google C++ Style Guide</a></li>
<li>较多人进行阅读, 有一些现有阅读笔记<a href="http://www.cnblogs.com/duguguiyu/archive/2008/10/02/1303095.html" target="_blank" rel="external">Chrome源码剖析</a></li>
<li>能够学习到比较全面各种子系统的设计知识, 如网络, 多线程, IO, 内存管理等</li>
<li>其项目中包含了若干Google的子项目, 也很值得阅读, 例如: libv8, gtest, gflags</li>
<li>源码地址: <a href="https://code.google.com/p/chromium/" target="_blank" rel="external">https://code.google.com/p/chromium/</a></li>
</ul>
<h3 id="STL"><a href="#STL" class="headerlink" title="STL"></a>STL</h3><ul>
<li>C++标准模板库, 日常开发必备</li>
<li>通过源码能够学习到模板编程基础, 相对于Boost来说可读性很高, 上手容易</li>
<li>通过学习STL实现能够更好的掌握STL的开发范式, 例如通过迭代器编程而不是传递容器, 使用或扩展STL中的算法</li>
<li>通过了解STL常用容器的底层实现也能更好的让我们再不同场景下选择合适的容器, 避免因误用造成时间空间的浪费</li>
<li>STL实现版本较多, 内部接口的编程风格不是很好, 建议通过SGI STL的源码进行阅读</li>
<li>源码地址: <a href="https://www.sgi.com/tech/stl/" target="_blank" rel="external">https://www.sgi.com/tech/stl/</a></li>
</ul>
禁止Visual Assist自动添加Override关键字
http://coney.github.io/2015/06/disable-override-keyword-for-visual-assist/
2015-06-01T06:32:21.000Z
2017-10-01T15:10:20.458Z
<h2 id="问题描述"><a href="#问题描述" class="headerlink" title="问题描述"></a>问题描述</h2><p>Visual Assist是一款历史悠久的Visual Studio插件, 能够极大的提升C++开发效率. 但是某些时候智能过了头, 反倒成了开发效率的绊脚石, 例如在实现虚方法(Implement Virtual Methods)时自动添加的<code>override</code>关键字.</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">SomeInterface</span> {</span></div><div class="line"><span class="keyword">public</span>:</div><div class="line"> <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">doSomething</span><span class="params">()</span> </span>= <span class="number">0</span></div><div class="line">};</div></pre></td></tr></table></figure>
<p>使用Implement Virtual Methods后, Visual Assist帮我们生成如下代码:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">SomeImplementation</span> :</span> <span class="keyword">public</span> SomeInterface {</div><div class="line"><span class="keyword">public</span>:</div><div class="line"> <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">doSomething</span><span class="params">()</span> override</span></div><div class="line"><span class="function"> </span>{</div><div class="line"> <span class="keyword">throw</span> <span class="built_in">std</span>::logic_error(<span class="string">"The method or operation is not implemented."</span>);</div><div class="line"> }</div><div class="line">};</div></pre></td></tr></table></figure>
<p>Visual Assist在<code>virtual void doSomething()</code>后面帮我们添加了一个<code>override</code>关键字, 这个关键是符合c++11标准的. 但是一些老旧的编译器并不支持<code>override</code>, 因此导致编译错误. 这使我们不得不手动删除所有生成方法后的<code>override</code>关键字.</p>
使用Mockcpp Mock C++静态函数
http://coney.github.io/2015/05/mock-static-function-with-mockcpp/
2015-05-06T07:22:10.000Z
2017-09-27T08:59:04.000Z
<p>传统测试中的Mock, 都是基于多态实现的, 也就是Mock面向接口的虚函数. 但是在C++的代码中, 经常会混入大量的C函数或是静态成员函数.<br>例如工厂函数, 单例函数, 或是C库中的函数甚至STL的算法等.</p>
<p>对于这些静态函数, 比较传统的做法是创建一个Wrapper, 用虚方法对这些静态函数进行包裹. 在测试的时候对Wrapper进行Mock便可控制被包裹的静态函数的行为:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">add</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y)</span></span>;</div></pre></td></tr></table></figure>
<p>可以通过Wrapper包裹为:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">Calc</span> {</span></div><div class="line"><span class="keyword">public</span>:</div><div class="line"> <span class="function"><span class="keyword">virtual</span> <span class="keyword">int</span> <span class="title">add</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y)</span> </span>{</div><div class="line"> <span class="keyword">return</span> ::add(x, y);</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure>
<p>但是对于存量代码, 这种重构并不现实(工作量及流程问题). 正当我们束手无策时, 我们发现mockcpp可以帮助我们解决一部分静态方法Mock的需求.</p>
VC中对SEH的扩展
http://coney.github.io/2014/04/seh-extension-in-vc/
2014-04-19T08:30:54.000Z
2017-09-27T08:59:04.000Z
<p>这篇文章是早前跟某同事探讨Windows SEH中<code>__finally</code>实现时研究的内容, 根据某书介绍, 异常处理函数都是通过<code>_EXCEPTION_REGISTRATION_RECORD</code>内的回调函数<code>Handler</code>实现的:</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> _<span class="title">EXCEPTION_REGISTRATION_RECORD</span></span></div><div class="line"><span class="class">{</span></div><div class="line"> <span class="class"><span class="keyword">struct</span> _<span class="title">EXCEPTION_REGISTRATION_RECORD</span> *<span class="title">Next</span>;</span></div><div class="line"> PEXCEPTION_ROUTINE Handler;</div><div class="line">} EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD;</div><div class="line"></div><div class="line">__try</div><div class="line">{</div><div class="line"> ...</div><div class="line">}</div><div class="line">__except( XXX )</div><div class="line">{</div><div class="line"> <span class="comment">// 这里是对应那个_EXCEPTION_REGISTRATION_RECORD 的第二个成员Handler</span></div><div class="line"> ...</div><div class="line">}</div></pre></td></tr></table></figure>
<p>但是对于<code>__finally</code>却没有介绍具体的实现方式. 通过调试器trace不到<code>__finally</code>的调用路径.<br>
古董街机修复之路
http://coney.github.io/2014/04/fixing-arcade-machine/
2014-04-07T08:33:24.000Z
2017-10-01T15:24:11.277Z
<p>加入Thoughtworks前参观西安Office时就已经注意到办公室角落的一台街机, 在入职后才知道此街机已经坏了有些年月. 机缘巧合, 加入硬件小组后了解到有修复游戏机的计划, 所以便有了以下的经历.</p>
<h2 id="方案选择"><a href="#方案选择" class="headerlink" title="方案选择"></a>方案选择</h2><p>开搞之前, 新宇和高亮已经把游戏机肚里的东西摸得一清二楚. 游戏机主板寄给某个淘宝店家后已杳无音讯, 屏幕则是一块接受RGBS信号的25寸显像管, 摇杆和按钮是最直接的按键开关, 闭合后会跟GND连通. 有了这些基本输入输出信息, 下一步就是选择合适的软硬件来重建主板.</p>
<p>回想曾经的街机经历, 无非也就两种选择: 一是到游戏厅玩真机, 第二种便是通过PC上的模拟器. 重买一个街机主板放进去肯定不是我们想要的方案, 所以我们基本确定思路就是通过PC主机+模拟器的方式. 比较常见的街机模拟器有winkawaks, nebula和MAME等, 相信不少人都有玩过:</p>
<p><img src="/images/2014/04/MAME.jpg" alt="MAME"><br>
防止Ubuntu启动时自动进入GUI
http://coney.github.io/2014/02/booting-ubuntu-without-x/
2014-02-06T13:56:15.000Z
2017-09-27T08:59:04.000Z
<p>为了实验几个需要X的小程序, 很不情愿的在Ubuntu Server上安装了Ubuntu-Desktop, 但是Ubuntu每次引导后自动进入Gnome实在是烦.</p>
<p>一般情况下想默认进入CLI的话只需要修改下runlevel, 可是我安装的Ubuntu(Server 12.04 LTS)默认的runlevel是2, Gnome也跑在level 2上. 貌似不能像往常一样通过修改<code>inittab</code>来禁用X.</p>
让mac下rvm支持更多的编译器
http://coney.github.io/2013/12/make_rvm_support_more_gcc_versions/
2013-12-13T03:50:40.000Z
2017-09-27T08:59:04.000Z
<p>通过rvm安装ruby-1.9.3-p484时, 发现rvm会尝试通过brew安装gcc46, 但在编译gcc46依赖的ppl011时产生错误, 导致整个安装流程失败. 我的机器上已经通过brew安装了更高版本的gcc49, rvm看起来还不够聪明去自动使用更新的编译器.</p>
<p>从网上搜索解决方案时看到这个commit:</p>
<p><img src="/images/2013/12/QQ20131210-1.png" alt="img"><br>
Java下"Failure initializing default system SSL context"的修复
http://coney.github.io/2013/12/fix_java_ssl_problem/
2013-12-08T01:21:09.000Z
2017-09-27T08:59:04.000Z
<p>今日准备用java + gradle体验下hello world, 结果在download jar包时卡了很久. 错误信息像这个样子:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">> Could not resolve org.eclipse.jetty:jetty-server:9.1.0.v20131115.</div><div class="line">Required by:</div><div class="line">:blog-search:1.0</div><div class="line">> Failure initializing default system SSL context</div></pre></td></tr></table></figure>
<p>从网上查了很多内容, 大部分都没有什么帮助, 后来发现并不是gradle的问题, 而是在使用java的https时证书有问题导致. 参考网上的资料, 要对keystore进行一些处理:</p>
<p><a href="http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.security.component.60.doc%2Fsecurity-component%2Fjsse2Docs%2Fcustomizingstores.html" target="_blank" rel="external">http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.security.component.60.doc%2Fsecurity-component%2Fjsse2Docs%2Fcustomizingstores.html</a><br>
Funny Commands
http://coney.github.io/2013/11/funny-commands/
2013-11-30T02:30:32.000Z
2017-09-27T08:59:04.000Z
<p>最近总是能够从其他同事那里学来一些有趣的命令, 害怕时间长忘记了, 所以开个帖子记录下.</p>
<h1 id="ipcalc"><a href="#ipcalc" class="headerlink" title="ipcalc:"></a>ipcalc:</h1><p>这个命令是用来计算IP或者子网的, 能够以漂亮的色彩分析ip或者子网的范围, 掩码等信息. 我比较喜欢用这个东西来查看类似192.168.0.0/22这种子网的范围.<br><img src="/images/2013/11/QQ20131130-2.png" alt="img"><br>
命令行编译arduino源码及上传执行
http://coney.github.io/2013/11/compile-and-upload-adruino-source-form-cli/
2013-11-09T02:34:49.000Z
2017-09-27T08:59:04.000Z
<p>Arduino官方提供了一个IDE, 集成了编辑, 编译, 上传和串口监视等功能, 但是这个基于java的IDE的编辑功能略弱. 所以想是否能使用其他的c++ IDE外加类似Makefile的命令行方式编译执行. 这样也能够在类似树莓派之类的设备上直接编译和烧录程序至arduino.</p>
<p>首先尝试带参启动arduino的IDE, 没有发现类似devenv.exe带参直接编译工程的功能. 之后在arduino主站搜索一番, 倒是发现了一个通过makefile的方法(<a href="http://playground.arduino.cc/Learning/CommandLine" target="_blank" rel="external">http://playground.arduino.cc/Learning/CommandLine</a>), 不过提供的库略坑爹. 折腾了半天后发现提供的uart.h里面没有mega2560的定义. 从IDE中提取的库也找不到这个定义. 只能搞一些较老的芯片, 遂放弃.</p>
<p>继续google, 发现另外一套基于python的命令行工具ino, 试用了下, 还是比较稳定的. ino的介绍可以看这里:<a href="http://inotool.org/" target="_blank" rel="external">http://inotool.org/</a> 网站上提供了多种安装方式, 因为我的树莓派是debian的系统, 所以相关的东西基本都是通过apt安装的.<br>
GO CI - 创建Pipeline
http://coney.github.io/2013/10/go-ci-pipeline/
2013-10-04T09:44:54.000Z
2017-09-27T08:59:04.000Z
<h1 id="创建Pipeline"><a href="#创建Pipeline" class="headerlink" title="创建Pipeline"></a>创建Pipeline</h1><p>装完了Go肯定要拿来试试效果, 这里使用了过去写过的一个C++小程序来测试整套Build Pipeline系统. 因为这个小程序比较简单, 就分成了两个Stages. 一个是测试, 另一个是编译App.</p>
<p>首先我们给Pipeline起一个名字:</p>
<p><img src="/images/2013/10/Screen-Shot-2013-10-05-at-上午1.08.42.png" alt="img"><br>
GO CI - 安装配置
http://coney.github.io/2013/10/go-ci-setup/
2013-10-02T05:46:56.000Z
2017-09-27T08:59:04.000Z
<p>什么是Go呢? Go是骚窝出品的一款持续交付(CD)产品, 类似于Hudson, Bamboo等CI服务. 作为一家专业的敏捷和持续交付咨询公司, Go从定位上就已经拉开了与其他同类产品的距离, 当别人还在搞CI的时候, 骚窝已经在玩CD了. 下面简单贴下安装和配置流程, 以及试用体验.</p>
<h1 id="安装Go-Server"><a href="#安装Go-Server" class="headerlink" title="安装Go Server"></a>安装Go Server</h1>
命令行参数解析 - Shell 脚本
http://coney.github.io/2013/07/parse-cli-arguments-in-shell-script/
2013-06-30T21:05:46.000Z
2017-09-27T08:59:04.000Z
<p>平时多少会用shell写点小工具, 而这些小工具运行后的第一件事就是解析参数, 这里总结了下shell脚本几种处理命令行参数的方法.</p>
<p>比较常见的做法就是解析bash内置的几个特殊变量, 例如直接遍历$*或者$@:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#/bin/sh</span></div><div class="line"><span class="built_in">echo</span> <span class="string">'args from \$*'</span></div><div class="line"><span class="keyword">for</span> arg <span class="keyword">in</span> $*; <span class="keyword">do</span></div><div class="line"> <span class="built_in">echo</span> <span class="variable">$arg</span></div><div class="line"><span class="keyword">done</span></div><div class="line"></div><div class="line"><span class="built_in">echo</span> <span class="string">'args from \$@'</span></div><div class="line"><span class="keyword">for</span> arg <span class="keyword">in</span> <span class="variable">$@</span>; <span class="keyword">do</span></div><div class="line"> <span class="built_in">echo</span> <span class="variable">$arg</span></div><div class="line"><span class="keyword">done</span></div><div class="line"></div><div class="line"><span class="built_in">echo</span> <span class="string">'args from "\$*"'</span></div><div class="line"><span class="keyword">for</span> arg <span class="keyword">in</span> <span class="string">"$*"</span>; <span class="keyword">do</span></div><div class="line"> <span class="built_in">echo</span> <span class="variable">$arg</span></div><div class="line"><span class="keyword">done</span></div><div class="line"></div><div class="line"><span class="built_in">echo</span> <span class="string">'args from "\$@"'</span></div><div class="line"><span class="keyword">for</span> arg <span class="keyword">in</span> <span class="string">"<span class="variable">$@</span>"</span>; <span class="keyword">do</span></div><div class="line"> <span class="built_in">echo</span> <span class="variable">$arg</span></div><div class="line"><span class="keyword">done</span></div></pre></td></tr></table></figure>
mac下gem install mysql和libv8时编译错误的处理
http://coney.github.io/2013/06/issuses-of-installing-mysql-and-libv8-on-mac/
2013-06-28T09:32:12.000Z
2017-09-27T08:59:04.000Z
<p>今天通过gem安装mysql和libv8时, 均遇到了编译错误, 尤其是mysql的比较晦涩:</p>
<pre><code>coney:cp-agentadmin$gem install mysql
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/Users/coney/.rvm/rubies/ree-1.8.7-2012.02/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** extconf.rb failed ***
...
Results logged to /Users/coney/.rvm/gems/ree-1.8.7-2012.02@customer-platform/gems/mysql-2.9.1/ext/mysql_api/gem_make.out
</code></pre>
直接改写std::string内存导致的问题
http://coney.github.io/2013/03/invalid-writing-std-string-cstr/
2013-03-26T21:24:43.000Z
2017-09-27T08:59:04.000Z
<p>今天帮一个同事查问题: 他写了一个全局的string变量, 在程序运行过程中可能会对该变量进行解析操作, 但是在持续运行过程中第二次访问到这个全局变量的时候, string的内容发生了改变. 他代码大体逻辑类似下面这样:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">process</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span> &rawstr)</span></span></div><div class="line"><span class="function"></span>{</div><div class="line"> <span class="built_in">string</span> delim = <span class="string">","</span>;</div><div class="line"> <span class="built_in">string</span> newstr = rawstr;</div><div class="line"> <span class="comment">// 认为这里会复制文本内容</span></div><div class="line"> <span class="built_in">printf</span>(<span class="string">"rawstr:%p newstr:%p\n"</span>, rawstr.c_str(), newstr.c_str());</div><div class="line"></div><div class="line"> <span class="keyword">char</span> *ptoken = strtok(<span class="keyword">const_cast</span><<span class="keyword">char</span> *>(newstr.c_str()), delim.c_str());</div><div class="line"> <span class="keyword">while</span> (ptoken)</div><div class="line"> {</div><div class="line"> <span class="comment">// process ptoken</span></div><div class="line"> ptoken = strtok(<span class="literal">NULL</span>, delim.c_str());</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> **argv)</span></span></div><div class="line"><span class="function"></span>{</div><div class="line"> <span class="built_in">string</span> str = <span class="string">"1,2,3,4"</span>;</div><div class="line"> <span class="built_in">printf</span>(<span class="string">"before:'%s'\n"</span>, str.c_str());</div><div class="line"> process(str);</div><div class="line"> <span class="built_in">printf</span>(<span class="string">"after:'%s'\n"</span>, str.c_str());</div><div class="line"> <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">}</div></pre></td></tr></table></figure>
c++声明接口未提供虚析构函数的后果
http://coney.github.io/2013/03/what-happens-when-cpp-destructor-is-not-virtual/
2013-03-23T01:13:30.000Z
2017-09-27T08:59:04.000Z
<p>这是一个比较低级的错误, 用C++模拟C#提供接口, 声明了纯虚函数, 看起来像这样:</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">ITestable</span></span></div><div class="line"><span class="class">{</span></div><div class="line"><span class="keyword">public</span>:</div><div class="line"> <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">Test</span><span class="params">()</span> </span>= <span class="number">0</span>;</div><div class="line">};</div></pre></td></tr></table></figure>
VS编译运行后可执行文件不能再次写入的问题
http://coney.github.io/2013/03/file-locked-issue-under-visual-studio/
2013-03-20T08:36:22.000Z
2017-09-27T08:59:04.000Z
<p>在公司和家里的电脑上都遇到这个问题, 编译运行程序后, 无论clean或者rebuild, 生成的exe都不能删除掉, 通过processhacker查看是system占用, 怀疑是杀软引用了exe的文件句柄. 可惜卸载杀软后问题同样出现. 提示信息如下:<br>