
[英]Accessing non const method from const object
我有一个C ++示例,我尝试在通过const getter访问的类成员上设置属性。 我希望这会给我d1->property().set_val(2);一个错误d1->property().set_val(2); 因为property()方法是const ,应该给我一个没有s ...
[英]Accessing non const method from const object
我有一个C ++示例,我尝试在通过const getter访问的类成员上设置属性。 我希望这会给我d1->property().set_val(2);一个错误d1->property().set_val(2); 因为property()方法是const ,应该给我一个没有s ...
[英]Const array of const strings and ERROR “not a compile-time constant”
我想制作const字符串的模块化枚举矩阵。 我做了两个typedef globals.h pages.h pages.c page_1.h page_1.c page_2.h page_2.c 问题1: warning我在联机C ...
[英]Passing string literal to function which expect string
让我们假设我有一个 function 期望参数是一个字符串(非常量)。 但正如我们所知,字符串文字本质上是 const 。 有什么方法可以将字符串文字传递给期望非常量的 function。 我知道这会导致错误,因为文字本质上是 const,但 function 期待非 const。 任何方式来铸造 ...
[英]How to inherit parent constants and access them?
如何从父 class 访问 const 变量? 我有一个 PI 常量,我想在 TCylinder class 中使用它,如何访问它? 我知道我可以使用 Math.PI,但对于未来我想知道 } ...
[英]Storing const* in const vector
我必须处理的相关接口代码包含两个函数,一个是检索对象,另一个是我必须将对象作为向量提交。 问题是,检索 function 返回const Object* ,但提交 function 需要const vector<Object*> 。 我知道这可以用const_cast<Object ...
[英]error: passing ‘const std::__cxx11::list<>’ as ‘this’ argument discards qualifiers
我有一个小问题,找不到解决方法。。 在 my.hpp 文件中,我声明了这两个函数和结构,但收到错误“将 'const std::__cxx11::list<>' 作为 'this' 参数丢弃限定符。” 我试图做的 in.cpp 文件: 我怎样才能使这项工作? ...
[英]Is it possible to use .reduce with a const?
我正在完成我的编码训练营中的一项作业。 他们要求我们使用.reduce 来得出一个值。 但是,他们使用 const 变量初始化了总值。 当我尝试使用 const 值解决这个问题时,它一直在抛出错误。 因为在我看来,你不能改变 const 值。 我只是用 let 替换了 const。 我不确定我是否 ...
[英]Is there a way to declare a public static const that will be defined in the source file using constexpr (and what difference is there)?
在我的 header 中,我声明了一个公共 static 常量,并在源文件中将其定义为 class 成员。 我想在源文件中定义它,因为我包含并使用它的常量,并且我不想包含在我的 header 中。 如果我在 header 中使用 static constexpr 它需要在那里定义。 header ...
[英]Can I legally write to the data pointed to by a constant vector, e.g. sort it?
我有一个常数 integer vector const vector<int> v = {5,1,3,2,4} 。 如何在不使用任何额外的 memory(如向量、数组等)的情况下对其进行排序。 ...
[英]How can i use variable value as variable name in other script?
我有一个带有配置文件的统一项目(用于动画名称) 在另一个脚本中,我想使用激活 animation 我的问题是将name_Of_The_Anim_I_Want_To_Activate.ToString()转换为实际的 animation 名称我可以使用哪个工具将name_Of_The_Anim_I_ ...
[英]Best way to init an unchanging byte slice
在 Go 中,您可以按如下方式初始化字节切片(在 Go Playground 上尝试)package main import ( "fmt" "encoding/hex" ) // doStuff will be called many times in actual appli ...
[英]Easiest way to modify a const variable's value
对于我的 CS class 我有一个变量const int m_vin ,在我的代码中我需要编辑这个值。 我的印象是无法编辑const变量。 我将如何 go 关于这个? 编辑:这里是m_vin的说明,它是名为 Vehicle 的 Object 的成员变量:m_vin,一个 const int,表示唯 ...
[英]Change value of static const int in c++
我需要更改static const int成员的值。 我知道这有点奇怪,但我需要它来克服我正在使用的框架给出的限制! 我已经尝试过了,但它不起作用,它会出现一个错误,说“未定义对 MyClass::staticConstMember 的引用”: ...
[英]Copy “pointer to const” to “pointer to non const” via memcpy
返回警告: 警告:初始化从指针目标类型中丢弃“const”限定符 [-Wdiscarded-qualifiers] 通过memcpy将指向const的指针复制到指向非const的指针以避免警告是否安全(定义明确的行为)? ...
[英]How should you create a std::experimental::observer_ptr to a non-const object that cannot mutate the value it points to?
这是将std::experimental::observer_ptr创建到不能改变它指向的值的非const object 的规范方法吗?auto i = int{0}; auto p = std::experimental::make_observer(&std::as_const(i) ...
[英]invalid conversion from 'const DList<int>* const' to 'DList<int>*' [-fpermissive] when returning an object
这是我的任务和链表的代码,我的任务是实现链表的迭代器类,我刚刚实现了开始和结束函数,当我运行测试器检查这些函数是否工作时,我得到了错误在返回 const_iterator object 时,在这些行下面出现“从 'const DList* const' 到 'DList*' [-fpermissi ...
[英]Do global constants still have to be initialized with constant expressions?
由于 GLSL 4.20 const限定的变量不再需要由常量表达式初始化。 但是当我真正尝试定义一个由非常量表达式初始化的全局const限定变量时,Mesa 会发出错误。 这是示例代码: 这是我测试编译的方式(以避免任何 OpenGL 代码):$ glsl_compiler --version 4 ...
[英]Can I pass char* to const char* in C?
我正在实现一个 function 将字符串转换为 C 中的双精度。 function 没有破坏性,即我不修改传递的字符串,我只是在 function 中读取它。 我想将 char*、const char* 以及字符串文字传递给 function。 以下 function 是否适合此目的? 我认为 ...
[英]Why is std::uniform_int_distribution<IntType>::operator() not const?
据我了解,当用于提取随机数时,分布不应改变。 例如,对于均匀分布,它的最小值/最大值在我们使用它生成随机数时不应该改变,那么为什么operator()不是 const 呢? ...
[英]How do I write a function starting with the keywork const - JavaScript?
我希望你一切都好。 我对编码很陌生,我正在尝试完成一个挑战,我必须创建一个 function 和 output 以控制台: 我没有得到的部分是简报要求我以关键字“const”(然后是 const 名称)开头。 我写了以下输出所需的内容,但我不确定这是否正确。 简报中要求我编写一个带有两个参数(国家 ...