草庐IT

compilers_and_libraries

全部标签

c++ - constexpr 类的设计 : merging constexpr and non-constexpr versions?

考虑一个在运行时只包装一个值的类:templateclassNonConstValue{public:NonConstValue(constType&val):_value(val){;}Typeget()const{return_value;}voidset(constType&val)const{_value=val;}protected:Type_value;};以及它的constexpr版本:templateclassConstValue{public:constexprConstValue(constType&val):_value(val){;}constexprTypeg

C++ typedef 和返回类型 : how to get the compiler to recognize the return type created with typedef?

#includeusingnamespacestd;classA{typedefintmyInt;intk;public:A(inti):k(i){}myIntgetK();};myIntA::getK(){returnk;}intmain(intargc,char*constargv[]){Aa(5);cout在这一行中,myInt未被编译器识别为“int”:myIntA::getK(){returnk;}如何让编译器将myInt识别为int? 最佳答案 typedef创建同义词,而不是新类型,因此myInt和int已经相同。问题

c++ - 算法 C/C++ : Fastest way to compute (2^n)%d with a n and d 32 or 64 bit integers

我正在寻找一种算法,允许我使用n和d32或64位整数计算(2^n)%d>.问题是即使使用多精度库也不可能将2^n存储在内存中,但也许存在计算(2^n)%d的技巧仅使用32位或64位整数。非常感谢。 最佳答案 看看ModularExponentiationalgorithm.这个想法不是计算2^n。相反,您可以在加电时多次降低模数d。Thatkeepsthenumbersmall.将方法与ExponentiationbySquaring结合起来,并且您可以仅在O(log(n))步内计算(2^n)%d。这是一个小例子:2^130%123

c++ - 我的 For 循环有什么问题?我收到警告 : comparison between signed and unsigned integer expressions [-Wsign-compare]

#include#include#include#includeusingnamespacestd;intmain(){vectorvector_double;vectorvector_string;...while(cin>>sample_string){...}for(inti=0;i 最佳答案 Whyisthereawarningwith-Wsign-compare?正如警告的名称及其文本所暗示的,问题在于您正在比较有符号整数和无符号整数。人们普遍认为这是一次意外。为了避免这个警告,你只需要确保的两个操作数(或任何其他比较运算

idea热部署及热部署插件(JRebel and XRebel)的配置使用及激活插件失败,提示【LS client not configued】

idea热部署及热部署插件(JRebelandXRebel)的配置使用及激活插件失败,提示【LSclientnotconfigued】idea热部署及热部署插件(JRebelandXRebel)的配置使用及激活插件失败,提示【LSclientnotconfigued】1、安装插件2、激活插件3、对JRebel进行一些配置:设置JRebel离线工作,并且部署时间设置为1s设置idea为自动编译使用JRebel&XRebel激活插件失败,提示【LSclientnotconfigued】idea热部署及热部署插件(JRebelandXRebel)的配置使用及激活插件失败,提示【LSclientnot

c++ - 编译器差异 : Interaction between alias resolution and name lookup

考虑这段代码:usingtype=long;namespacen{usingtype=long;}usingnamespacen;intmain(){typet;}这可以在Clang3.7和GCC5.3上干净地编译,但是MSVC19*给出以下错误消息:main.cpp(9):errorC2872:'type':ambiguoussymbolmain.cpp(1):note:couldbe'longtype'main.cpp(4):note:or'n::type'这段代码格式是否正确?标准的哪一部分说明在歧义检查之前是否已解析别名?请注意,如果您更改其中一个别名,Clang和GCC都会给

c++ - Visual Studio 2015 (C++) : Stop compile on first build error (not first project)

VisualStudio2015检测到编译错误时如何停止编译?我的意思是第一次构建错误(可能是第一个.cpp),而不是第一个项目,因为它需要太多时间。(我只有1个项目。)名为"StopOnFirstBuildError"的扩展不是答案,因为它停止在有错误的第一个项目。问题(更详细)当我按下F5或Ctrl+Shift+B时,编译器会编译所有(或部分)文件。在我的例子中,它可以只用5秒检测到一些错误,所以我希望它现在停止编译。但是,VS2015变得无响应。对Ctrl+Break也有很强的抵抗力。我大约需要30秒才能导航到错误位置。如何在出现第一个编译错误时自动停止编译过程?历史有anold

c++ - xvalues : differences between non class types and class types

考虑下面的最小示例:#includestructS{};intmain(){Ss;std::move(s)=S{};}它编译没有错误。如果我改为使用非类类型,则会收到错误。例如,以下代码无法编译:#includeintmain(){inti;std::move(i)=42;}枚举、作用域枚举等也是如此。错误(来自GCC)是:usingxvalue(rvaluereference)aslvalue这背后的原理是什么?我想这是对的,但我想了解我可以对除非类之外的所有类型执行此操作的原因是什么。 最佳答案 C++允许对类对象右值进行赋值,

C++ 函数到指针的隐式转换 : which compiler is right? Clang 和 GCC 不同意

templatestructA{};voidfunc();Aa;//sameresultwithAa;此代码使用Clang(包括最新的8.0.0)编译,但不能使用GCC(包括最新的9.1)编译。GCC说:错误:'void()'不是模板非类型参数的有效类型哪个编译器是正确的,为什么?更新我猜GCC是错误的,因为以下代码在Clang和GCC上都可以编译:templatestructA{};voidfunc();Aa;//sameresultwithAa;因此与GCC在第一个示例中的报告相反,void()似乎是“模板非类型参数的有效类型” 最佳答案

c++ - 如何在运行时摆脱 LD_LIBRARY_PATH?

我正在构建一个使用英特尔IPP的C++应用程序图书馆。该库默认安装在/opt中,需要您设置LD_LIBRARY_PATH来编译和运行您的软件(如果您选择共享库链接,我就是这么做的)。我已经修改了我的configure.ac/Makefile.am这样我在编译时就不需要设置那个变量了,但是我在运行时仍然找不到共享库-时间;我该怎么做?我正在使用g++使用-Wl,-R/path/to/libdir标记进行编译更新1:实际上我的二进制程序有一些正确链接的IPP库,但只有一个不是:$lddmyprogramlinux-vdso.so.1=>(0x00007fffa93ff000)libippa