转化会失去限定符,但实际上并非如此
Conversion loses qualifiers, but doesn't really
这有点类似,但也有点不同:c++ "转换失去限定符"编译错误
在我的代码,我得到以下错误:
错误C2440:"初始化":无法从"const git_commit"转换*const *' to 'const git_commit **'
正如我所理解的,从T**赋值到const T**将允许违反constness规则,在我给出的例子中,也就是说,从const T*const *赋值到const T**实际上获得了constness,而没有失去任何,那么这在哪里/为什么是一个问题?
const git_commit * const *
指向指向常量git_commits的指针数组
const git_commit * *
指向指向常量git_commits的可变数组的指针
将const数组赋值给可变数组会丢失const。
int const x = 7;
std::cout << x << 'n'; // compiler can optimize to 7
int const* const px = &x;
std::cout << *px << 'n'; // compiler can optimize to 7
int const*const* ppx = &px;
std::cout << **ppx << 'n'; // compiler can optimize to 7
int const** ppx_cheat = ppx; // illegal, but presume we are allowed to do it
int const y = 1;
int const* py = &y;
*ppx_cheat = py;
std::cout << **ppx << 'n'; // compiler can optimize to 7, *but is wrong*
相关文章:
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 为什么我的删除节点函数实际上没有删除节点?
- 其中降频广播实际上是有用的
- "delete"在 C++ 中实际上做了什么?
- C++:实际上不是从二进制文件中读取
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 您好,我实际上想了解以下代码.有人可以详细说明代码它到底在做什么吗?为什么它会在第 31 行崩溃
- 为什么我们实际上需要运行时多态性?
- FlatBuffers C++ reinterpret_cast访问实际上是未定义的行为吗?这样做实际上可以吗?
- 特征实际上扩展了稀疏矩阵
- *(int*)&data[18]在这段代码中实际上做了什么?
- C ++相同的字符串不相等(实际上是char*)
- 成员函数的"this"参数具有"const"类型,但我的函数实际上不是"const"
- 使用带有 std::cout 的单引号打印字符串实际上打印了数字
- 为什么编译器无法弄清楚构造函数实际上是 constexpr?
- 实际上,C++11 中 std::atomic 的内存占用量是多少?
- SQLHANDLE-Parameters:函数不接受x个参数(但实际上确实如此)
- Cppcheck 静态代码分析器实际上可以检测到不太常见的警告(如 "Relative Path Traversal (CWE-23)" 或"Buffer Under-read(CWE-127)")吗
- 转化会失去限定符,但实际上并非如此
- 为什么is_constructible声称某物是可构造的,而实际上并非如此?