草庐IT

static-compilation

全部标签

c++ - Visual Studio - 升级后为 "Unknown Compiler version"

我有一个VisualStudio2015C++项目,我想升级到VS2017。当我第一次在VS2017中打开我的项目时,我已经拒绝了升级我的项目的自动提示(不确定我想升级到时间)所以我不能那样更新我的项目。相反,我只是去了我的项目:属性->配置属性->常规我在那里将“平台工具集”选项更新为“VisualStudio2017(v141)”,并将“WindowSDK版本”从Windows8.1更改为10.0.16299.0。执行此手动升级后,我现在在构建时收到警告:Unknowncompilerversion-pleaseruntheconfiguretestsandreporttheres

c++ - 演绎指南、模板和子对象 : which compiler is right?

考虑以下片段:structS{S(){}templatestructT{T(B&&){}};templateT(B&&)->T;};intmain(){S::Tt{0};}铿锵acceptsit而GCCrejectsthecode出现以下错误:prog.cc:10:5:error:deductionguide'S::T(B&&)->S::T'mustbedeclaredatnamespacescope这是有效的代码吗?哪个编译器是正确的,GCC还是Clang? 最佳答案 根据http://en.cppreference.com/w/

c++ - 临时 : No compiler warning? 的绑定(bind)常量&

我有一个TestClass和一个const&成员变量。我从不同的地方和自己的经验知道,使用临时值的引用来初始化此const&是个坏主意。所以我很惊讶以下代码可以正常编译(使用gcc-4.9.1、clang-3.5和scan-build-3.5)但无法正常运行。classTestClass{public://removingthe"reference"wouldremovethetemporary-problemconststd::string&d;TestClass(conststd::string&d):d(d){//"d"isaconst-ref,cannotbechangedat

C++ static_cast 和引用

structA{};structB:A{};intmain(){Aa;A&a_ref=a;static_cast(a);//*1static_cast(a_ref);//*2return0;}(*1)产生错误,我明白为什么。(*2)编译正常,但为什么呢?而且,只要它编译并假设B包含一些属性,如果我将a_ref转换为B&然后尝试访问属性会怎样?我想我会遇到运行时错误或其他问题。所以,正如我所看到的,有一种情况会导致崩溃,并且没有办法避免它,这与dynamic_cast不同,后者可以检查转换结果是否为null或输入代码在try-catch区域。我如何处理这种情况,我需要转换引用并确保我真的

c++ - 如何在 C++ 中将 static_assert 用于 constexpr 函数参数?

我的库中有几个简短的constexpr函数可以执行一些简单的计算。我在运行时和编译时上下文中都使用它们。我想在这些函数的主体中执行一些断言,但是assert(...)在constexpr函数和static_assert中无效(...)不能用于检查函数参数。例子:constexprintgetClamped(intmValue,intmMin,intmMax)noexcept{assert(mMinmMax?mMax:mValue);}有没有办法检查函数是否在运行时或编译时常量中执行,并且仅当它在运行时执行时才执行断言-时间?constexprintgetClamped(intmValu

c++ - static_assert - 一种动态自定义错误消息的方法

有没有办法让static_assert的字符串动态自定义然后显示?我的意思是://pseudocodestatic_assert(Check_Range::value,"Valueof"+typeof(T)+"typeisnotsogood;)"); 最佳答案 没有,没有。但这并不重要,因为static_assert是在编译时求值的,如果出现错误,编译器不仅会打印消息本身,还会打印实例堆栈(在模板的情况下)。看看这个综合示例inideone:#includetemplatestructIsInteger{staticboolcons

c++ - 重载 static_cast?

所以,前几天我参加了考试,其中一个问题与此非常相似:我们有一个类叫做Square其中包含一个变量intside.我们怎样才能使cout(aSquare)成为可能会打印出aSquare的面积吗?这可能吗? 最佳答案 有可能做到这一点,但不能通过重载static_cast().您可以通过重载类型转换运算符来实现:classSquare{public:Square(intside):side(side){}operatorint()const{returnside*side;}//overloadedtypecastoperatorpri

c++ - 为什么报错LINK2005 : object already defined error disappears when I declare the object as static

我在头文件中定义了以下结构和结构对象,如下所示:structSTConfigurationDetails{boolbAutoStart;boolbAutoLog;boolbAutoScan;boolbAutoMount;boolbAutoOpen;boolbAutoDetectLast;};structSTConfigurationDetailsg_objConfigurationDetails;在自己的头文件中,我同时拥有使用g_objConfigurationDetails的方法和方法体。当我将头文件包含到另一个cpp文件并调用该方法时,这工作正常。但是当我将头文件添加到另一个cp

Java 互操作性 : how to declare a compile-time array constant in Kotlin?

我有这个Javaannotationdeclaration并想在Kotlin中使用它classCurlCommand{Parameter(names="-groups",description="Comma-separatedlistofgroupnamestoberun")vargroups:Array?=null}编译器报告TYPE_MISMATCH必需:kotlin.Array找到:kotlin.String我试过了Parameter(names=Array(1,{i->"-groups"}),description="Comma-separatedlistofgroupname

Java 互操作性 : how to declare a compile-time array constant in Kotlin?

我有这个Javaannotationdeclaration并想在Kotlin中使用它classCurlCommand{Parameter(names="-groups",description="Comma-separatedlistofgroupnamestoberun")vargroups:Array?=null}编译器报告TYPE_MISMATCH必需:kotlin.Array找到:kotlin.String我试过了Parameter(names=Array(1,{i->"-groups"}),description="Comma-separatedlistofgroupname