草庐IT

make_them_different

全部标签

c++ - 使用可变参数模板重载函数模板 : Intel c++ compiler version 18 produces different result from other compilers. intel 错了吗?

考虑以下代码片段:templateclassA,typename...Ts>inta(Aarg){return1;//Overload#1}templateinta(Aarg){return2;//Overload#2}templatestructS{};intmain(){returna(S());}在使用模板类的实例调用函数a时,我希望编译器选择更特殊的函数重载#1。根据compilerexplorer、clang、gcc和17版之前的英特尔实际上会选择重载#1。相反,后来的英特尔编译器版本(18和19)选择重载#2。是代码定义不正确还是最新的英特尔编译器版本有误?

c++ - 使用 mingw-w64 工具链时,以 Release模式链接的 Regex Boost 库会发出 "duplicate section has different size"警告

在Release模式下链接我的项目时,我收到以下警告:myProject-libs/release/libboost_regex-mt-s-1.50.0.a(cpp_regex_traits.o):duplicatesection`.data$_ZZN5boost16cpp_regex_traitsIcE21get_catalog_name_instEvE6s_name[boost::cpp_regex_traits::get_catalog_name_inst()::s_name]'hasdifferentsize我怀疑原因可能是boost库的编译选项与我在项目中使用的选项不同,但我

c++ - 调用 std::adjacent_difference() 时的隐式转换

我想获得vector中相邻点之间的距离vector:structPoint{doublex,y,z;}vectoradjacent_distances(vectorpoints){...}我认为stl::adjacent_difference()如果我简单地提供一个函数来找到两点之间的距离,我会成功的:doublepoint_distance(Pointa,Pointb){returnmagnitude(a-b);//implementationdetailsareunimportant}因此,我希望这会奏效,vectoradjacent_distances(vectorpoints)

c++ - 为什么我不能使用 std::make_shared 的实例化作为指向函数的指针?

当类具有默认构造函数时,我可以使用std::make_shared的实例化,就像使用指向函数的指针一样。这可能是因为实例化的模板必须编译并存储在内存中,并且它的地址必须存在。#include#includeclassDefaultConstructible{};typedefstd::function()>Generator;intmain(){Generatorgenerator(std::make_shared);std::shared_ptrdefConst=generator();return0;}但是当我添加一个非平凡的构造函数时,同样的事情失败了:#include#incl

java - C++ 和 Java 数组声明/定义 : differences

我的问题真的很简单(这并不意味着答案会很简单..:D)为什么C++中的数组将大小作为类型的一部分,而Java中却没有?我知道Java数组引用变量只是指向堆上数组的指针,但C++指向数组的指针也是如此,但即使那样我也需要提供一个大小。先分析一下C++://inC++://anarrayonthestack:intarray[*constexpr*];//abidimensionalarrayonthestack:intm_array[*constexpr1*][*constexpr2*];//amultidimensionalarrayonthestack:intmm_array[*co

c++ - 返回 std::make_unique<SubClass> 是如何工作的?

我有一个基类及其子类:classBase{public:virtualvoidhi(){cout尝试创建一个辅助函数来创建一个Derived对象的唯一指针。1)这个有效:std::unique_ptrGetDerived(){returnstd::make_unique();}2)但是,这个编译失败:std::unique_ptrGetDerived2(){autoa=std::make_unique();returna;}3)std::move有效:std::unique_ptrGetDerived3(){autoa=std::make_unique();returnstd::mov

c++ - 尝试 'Make' CUDA SDK,ld 找不到库,ldconfig 说可以

我知道还有很多其他问题与这个问题类似,但那里提出的解决方案都不适合我基本上,制作SDK示例文件时,我得到/usr/bin/ld:cannotfind-lcuda这将是一个足够简单的“找到库并将其扔给ldconfig”,除了ldconfig已经说它有它......$sudoldconfig-v|grepcuda/usr/local/cuda/lib64:libcudartemu.so.3->libcudartemu.so.3.0.14libcudart.so.3->libcudart.so.3.0.14/usr/local/cuda/lib:libcudartemu.so.3->libc

c++ - std::make_shared 构造函数中的参数个数

在VisualStudio2010/2011中缺少可变参数模板(仍然!),采用大量参数的构造函数可能会出现问题。例如,以下不会编译:MyMaterials.push_back(std::make_shared(MyFacade,name,ambient,diffuse,specular,emissive,opacity,shininess,shininessStrength,reflectivity,bumpScaling,maps,mapFlags));,因为它有13个参数,我认为make_shared仅限于arg0到arg9。明显的解决方法是两部分构造,但我希望避免这种情况。除了使

c++ - std::make_unique 可以与抽象接口(interface)一起使用吗?

考虑以下代码行:autosource1=std::unique_ptr(newGpsDevice(comPort,baudrate));autosource2=std::unique_ptr(newGpsLog(filename));如何使用VS2013支持的新std::make_unique函数来编写?有可能吗?**我的问题是我不知道如何告诉std::make_unique要实例化哪种对象。因为只有构造函数的参数被传入,所以似乎无法控制它。 最佳答案 std::unique_ptrbase_ptr=std::make_unique

c++ - `std::make_shared<POD>()` 值是否初始化我的 POD?

是否std::make_shared()值初始化我的POD?如果是,这是标准保证的吗?如果不是(正如我怀疑的那样),有没有办法做到这一点?我猜std::make_shared(POD())会做,但这是我应该做的吗? 最佳答案 是的,它是值初始化的,这是由标准保证的:§20.7.2.2.6,2:(关于make_shared)Effects:AllocatesmemorysuitableforanobjectoftypeTandconstructsanobjectinthatmemoryviatheplacementnewexpress