草庐IT

dynamic_pointer_cast

全部标签

c++ - MAC 操作系统 : dynamically linked library not found despite correct rpath

我有一个(相对)大的C++项目,它在ubuntu上编译和运行良好(使用cmake/catkin)。它在macos上编译得很好,但是当尝试启动可执行文件时,我收到错误消息:dyld:Librarynotloaded:.dylibReferencedfrom:/Reason:imagenotfound运行命令时:otool-l|grepLC_RPATH-A2我得到输出:cmdLC_RPATHcmdsize64path(offset12)cmdLC_RPATHcmdsize24path/sw/lib(offset12)cmdLC_RPATHcmdsize32path/usr/X11/lib(

c++ - Catch.hpp 单元测试 : How to dynamically create test cases?

我正在使用CATCHv1.1build14对我的C++代码进行单元测试。作为测试的一部分,我想检查代码中几个模块的输出。没有固定数量的模块;可以随时添加更多模块。但是,测试每个模块的代码是相同的。因此,我认为将测试代码放在for循环中是最理想的。事实上,使用catch.hpp,我已经验证了我可以在测试用例中动态创建部分,其中每个部分对应一个模块。我可以通过将SECTION宏包含在for循环中来做到这一点,例如:#include"catch.hpp"#include#include#include"myHeader.h"TEST_CASE("Moduletesting","[module

c++ - `static_cast<volatile void>` 对优化器意味着什么?

当人们试图在各种库中执行严格的基准测试时,我有时会看到这样的代码:autostd_start=std::chrono::steady_clock::now();for(inti=0;i这里使用volatile来防止优化器注意到被测代码的结果被丢弃,然后丢弃整个计算。当被测代码没有返回值时,说它是voiddo_something(int),然后有时我会看到这样的代码:autostd_start=std::chrono::steady_clock::now();for(inti=0;i(do_something(i+j));autostd_stop=std::chrono::steady_

c++ - 非静态成员函数的 std::add_pointer 实现

这个问题是Aquestionregardingtheimplementationofstd::add_pointer的后续问题下std::add_pointer有如下引用:Otherwise(ifTisacv-orref-qualifiedfunctiontype),providesthemembertypedeftypewhichisthetypeT.基于阅读Non-staticmemberfunctions:const-,volatile-,andref-qualifiedmemberfunctions,我的理解是对于具有给定cv和/或ref资格的非静态成员函数,a)函数的cv限定

c++ - "static_cast<To>(from)"当且仅当 "To to{from}"时,或者不是?

昨天在回答别人问题的过程中惊讶地发现gcc4.7.2包含特征模板std::is_explicitly_convertible,定义作为std::is_constructible_convertible的倒数:///is_explicitly_convertibletemplatestructis_explicitly_convertible:publicis_constructible{};搜索paper-trail,发现这个trait不应该有到过那里。bug有人提出反对将其包含在该版本的C++11标准库,它在gcc4.8.0中被删除。该错误报告指出std::is_explicitly

c++ - 将 bool R vector 传递给 C dynamic_bitset

将Rboolvector传递给C++dynamic_bitsetvector的最佳方法是什么?有没有一种方法可以使用指针和vector长度来构造一个dynamic_bitset对象,就像vector类一样?您会推荐使用Rcpp吗?感谢您的帮助和时间... 最佳答案 我只想创建dynamic_bitset像这样:#include#includeusingnamespaceRcpp;//[[Rcpp::export]]voidcreate_dynamic_bitset(LogicalVectorx){intn=x.size();boos

c++ - Qt 5 : const char * QString cast

在Qt4中,可以自动将QString转换为“constchar*”,例如我可以将QString传递给需要“constchar*”的函数。voidmyFunction(constchar*parameter);QStringmyString;myFunction(myString);//worksinQT4然而,在Qt5中,我会收到“错误C2440:‘typecast’:无法从‘QString’转换为‘constchar*’”(这是VisualC++2008编译器,其他编译器会抛出类似的东西)。如果我对文档的理解正确,那是因为QT5中不再包含Qt3兼容层。当然,我可以更改函数调用myFu

c++ - boost::lexical_cast 和 double——奇怪的行为

为什么当我写"2.01"和"2.02"时,下面的代码会给我不同的结果?#include#include#includeintmain(){conststd::stringstr="2.02";try{constdoubleb=boost::lexical_cast(str)*100.0;std::cout(b);std::cout输出double:202int:202但是如果我将"2.02"更改为"2.01"它会给我以下输出:double:201badlexicalcast:sourcetypevaluecouldnotbeinterpretedastarget为什么?我正在使用Vis

c++ - 将 lexical_cast 字符串提升为两倍

我遇到了转换问题,希望得到您的帮助。我正在使用gcc4编译器,但我对gcc4的使用非常有限。我想将std::string转换为double。std::stringaQuantity=aRate.getQuantity();std::stringaAmount=aRate.getAmount();//aAmount="22.05"doubledQuantity=boost::lexical_cast(aQuantity);doubledAmount=boost::lexical_cast(aAmount);//dAmount=22.050000000000001顺便说一句,我也试过ato

c++ - reinterpret_cast 右值和优化

我正在将一堆代码转换为使用C++风格的转换(在-Wold-style-cast的帮助下)。我并不完全相信它对原始变量的使用,但总的来说我是C++风格转换的新手。一个问题发生在一些字节序转换代码中。当前代码如下所示:#defineREINTERPRET_VARIABLE(VAR,TYPE)(*((TYPE*)(&VAR)))//...uint16_treverse(uint16_tval){/*stufftoreverseuint16_t*/}int16_treverse(int16_tval){uint16_ttemp=reverse(REINTERPRET_VARIABLE(val,