草庐IT

gravity_value_t

全部标签

javascript - 为 QScriptEngine 重新定义 "Undefined Value"函数时返回 "print()"有什么意义?

[背景]QScriptEngine的默认print()函数将结果打印到QtCreatorIDE的终端以进行调试。因此,如果我们要自己制作ECMA脚本解释器,则必须将输出重定向到我们的文本编辑器。这部分文件"MakingApplicationsScriptable"自Qt4.3以来保持不变。第"Redefiningprint()":QtScriptprovidesabuilt-inprint()functionthatcanbeusefulforsimpledebuggingpurposes.Thebuilt-inprint()functionwritestostandardoutput

c++ - std::is_same<t,t>::value 总是为真吗?

我继承了一些看起来像这样的代码://////Aspecializablefunctionforconvertingauser-definedobjecttoastringvalue///templatestd::stringto_string(constvalue_type&value){static_assert(!std::is_same::value,"Unspecializedusageofto_stringnotsupported");return"";}//////Aspecializablefunctionforconvertingauser-definedobjectf

c++ - 为什么在 C++ 中不允许使用 int& a = <value>?

我正在阅读C++中的引用。它说int&a=5给出了编译时错误。在ThinkinginC++-BruceEckel中,作者说编译器必须首先为int分配存储空间并生成绑定(bind)到引用的地址。存储必须是const因为改变它没有意义。我现在很困惑。我无法理解其背后的逻辑。为什么不能更改存储中的内容?我知道根据C++规则它是无效的,但为什么呢? 最佳答案 "Thestoragemustbeconstbecausechangingitwouldmakenosense."如果你希望a是对一个const值的引用,你必须将它声明为const,因

c++ - STL容器中的value_type有什么用?

value_type在STL容器中有什么用?来自MSDN://vector_value_type.cpp//compilewith:/EHsc#include#includeintmain(){usingnamespacestd;vector::value_typeAnInt;AnInt=44;cout我不明白value_type在这里实现了什么?变量也可以是int吗?使用它是因为编码人员懒于检查vector中存在的对象类型吗?我觉得这些也跟它差不多allocator_type,size_type,difference_type,reference,key_type等..

c++ - 错误处理 : return value vs exception in C++

在询问捕获“除以0”异常的过程中,我发现使用C++,我们无法做到这一点。我的意思是,除以0不会抛出std::exception。我发现的一些提示是我必须检查值,然后自行抛出异常。我说这很令人困惑,因为我认为C++采用异常思想是为了取代“良好的旧C/UNIX通过返回值方法报告错误”。这是我的问题问题1:为什么C++在除以0时不会抛出std::exception错误?这背后有什么原因吗?Q2:通常,C++用户使用什么错误处理方案?总是报错,异常是除以0错误?Q3:一般来说,OOP语言更喜欢(甚至强制)使用异常。这是正确的吗? 最佳答案

c++ - 错误 [Pe513] : a value of type "void *" cannot be assigned to an entity of type "uint8_t *"

我正在尝试将C项目转换为C++。在C项目中,我在编译成C++时遇到了这个错误:Error[Pe513]:avalueoftype"void*"cannotbeassignedtoanentityoftype"uint8_t*"下面的代码给出了这个错误:#defineRAM32Boundary0x20007D00uint8_t*pNextRam;pNextRam=(void*)RAM32Boundary;//loadupthebaseram谁能解释一下这是在C中做什么以及如何将其转换为C++? 最佳答案 C允许与void*之间的隐式转

C++ 运算符 () 和 'using' 声明 : Left operand must be l-value error

下面的例子说明了一个更复杂但没有什么不同的问题,我一直在努力优雅地解决这个问题。我有一组必须专门化的模板,在这样做时,在每个专门化中实现两个接口(interface)中的一个或两个:可读和可写。Specific实现了这两个接口(interface),然后使用main进行测试:classReadable{protected:intvalues[3];public:Readable(){//Doesnothing.}intoperator()(inti)const{returnvalues[i];}};classWritable:publicReadable{public:Writable

c++ - C++11 中的缩小转换 : what is the "actual value after conversion"?

以下代码在C++11中是否合法?int16_tx{0xaabb};int64_txxxx{0xaaaabbbbccccdddd};代码来自《TheC++ProgrammingLanguage》第4版(第150页)。我们知道,列表初始化是不允许窄化转换的,在标准的窄化转换定义中,我们有:Anarrowingconversionisanimplicitconversion—[...]—fromanintegertypeorunscopedenumerationtypetoanintegertypethatcannotrepresentallthevaluesoftheoriginaltyp

c++ - 有什么能阻止 std::optional::value_or() 有条件地 noexcept 吗?

这是value_or()的定义来自C++17标准:templateconstexprTvalue_or(U&&v)const&;Effects:Equivalentto:returnbool(*this)?**this:static_cast(std::forward(v));Remarks:Ifis_copy_constructible_v&&is_convertible_visfalse,theprogramisill-formed.(右值重载类似)value_or的效果被描述为等同于returnbool(*this)?**this:static_cast(std::forward

c++ - 为什么 `assert` 宏即使与 `NDEBUG` 也有值(value)?

环境:$g++--versiong++(Ubuntu7.4.0-1ubuntu1~18.04)7.4.0众所周知,在包含assert.h之前定义的NDEBUG可以禁用用于调试的类函数宏assert(卡塞特)。但是,在我的环境中阅读/usr/include/assert.h,我发现了下面的代码。#ifdefined__cplusplus&&__GNUC_PREREQ(2,95)#define__ASSERT_VOID_CASTstatic_cast#else#define__ASSERT_VOID_CAST(void)#endif#ifdefNDEBUG#defineassert(exp