草庐IT

const-reference

全部标签

opencv - libopencv_calib3d : undefined reference to `std::__throw_out_of_range_fmt(char const*, …)@GLIBCXX_3.4.20'

我提到了this在我的RaspberryPi2上安装OpenCV(它运行在最新的Raspbian上,内核版本为4.1.7-v7)。由于依赖项错误,我无法安装libgtk2.0-dev,但我能够毫无错误地安装OpenCV。我正尝试在Qt中为我的RaspberryPi2交叉编译一些简单的OpenCV代码。但是我在链接器阶段遇到以下错误:/usr/local/lib/libopencv_calib3d.so:undefinedreferencetostd::__throw_out_of_range_fmt(charconst*,...)@GLIBCXX_3.4.20我的代码是:myFunc{

c++ - 为什么 -fsanitize=undefined 导致 "undefined reference to typeinfo"?

以下测试用例,从真实世界的应用程序中缩减而来,无法与-fsanitize=undefined链接(使用GCC6.1.1),但没有它也能正常链接。谁能告诉我为什么?似乎与Qt/QObject、-fvisibility=hidden、-fsanitize=undefined的组合有关,但问题到底出在哪里超越我。lib1.h:#includeclassMyObject:publicQObject{public:MyObject(QObject*parent=nullptr);~MyObject();voidmyMethod();};lib1.cc:#include"lib1.h"#defin

c++ - remove_reference 如何禁用模板参数推导?

根据thislink,std::forward不允许模板参数推导,而std::remove_reference正在帮助我们实现这一目标。但是,使用remove_reference如何防止此处发生模板推导?templateS&&forward(typenamestd::remove_reference::type&t)noexcept{returnstatic_cast(t);} 最佳答案 S在表达式typenamestd::remove_reference::type中是一个非推导上下文(特别是因为S出现在使用qualified-i

c++ - 从 std::true_type 继承 vs static constexpr const bool 成员

我知道这不是一个非常尖锐的问题。使用一个比另一个有优势(编译时间、依赖性、调试符号大小、可用性、可读性等)吗?templatestructIsSharedPtr:std::false_type{};对比templatestructIsSharedPtr{staticconstexprboolvalue=false;};相关问题...templatestructS;templatestructS{};templatestructS{};对比templatestructS;templatestructS{};templatestructS{}; 最佳答案

c++ - 为什么有变异的 Boost.Range 算法的 const 重载?

Boost.Range的文档(和实现)显示了以常量引用作为参数的变异算法的重载。例如Boost.Range'sSortdocumentation显示:templateRandomAccessRange&sort(RandomAccessRange&rng);templateconstRandomAccessRange&sort(constRandomAccessRange&rng);templateRandomAccessRange&sort(RandomAccessRange&rng,BinaryPredicatepred);templateconstRandomAccessRang

c++ - 为什么将 const (...)& 放在 C++ 中

我想知道-为什么将const(...)&放在C++中是个好主意?我在一些类(class)教程中找到了这段代码。我知道const正在使某些东西保持不变并且无法更改,而&正在将它传递给函数。为什么两者都做?如果我不能改变某些东西,我为什么要把它传递给函数?这是一个例子:classCVector{public:intx,y;CVector(){};CVector(inta,intb):x(a),y(b){}CVectoroperator+(constCVector&);};CVectorCVector::operator+(constCVector¶m){//exampleCVect

c++ - C++ 中的异常处理 Terminate 在抛出 'char const*' 的实例后调用

错误:抛出“charconst*”实例后调用终止终止应用程序已要求运行时以不寻常的方式终止它。请联系应用程序的支持团队。当我这样做时,我不确定是什么导致编译器崩溃。有任何想法吗?对编程有点陌生。#include#includeusingnamespacestd;//TemplateforMaximumtemplateXMaximum(Xarg1,Xarg2){if(arg1>arg2)returnarg1;elsereturnarg2;}//TemplateforMinimumtemplateMMinimum(Marg1,Marg2){if(arg1>arg2)returnarg2;e

c++ - Clang 无法从基类中找到 const 模板成员函数

以下C++文件:structBase{templatevoidf(T&&)const{}};structDerived:Base{templatevoidf(T&&)const{}usingBase::f;};intmain(){Derivedconstcd;cd.f('x');}用GCC编译得很好,但用Clang编译不好:$g++-7.3.0-std=c++11test.cpp-otest-Wall-Wextra$g++-7.2.0-std=c++11test.cpp-otest-Wall-Wextra$g++-6.4.0-std=c++11test.cpp-otest-Wall-W

c++ - 在这种情况下,有人可以解释 "reference"和 "pointer"之间的区别吗?

当我读到litbanswertothisquestion,我了解到通过引用传递数组可以让我们获得它的大小。我只是玩了一点代码,并尝试通过引用传递一个“函数”,令人惊讶的是(至少对我而言),这段代码编译:voidexecute(void(&func)())//funcispassedbyreference!{func();}上一个函数和这个函数有什么区别吗:voidexecute(void(*func)())//funcispassedbypointer!{func();}我用VC2008试过了,在每种情况下它都会产生不同的输出。奇怪的是编译器在函数指针的情况下更好地优化了代码:void

c++ - 需要澄清 C 风格、重新解释和 const 转换

我假设C风格的转换(不鼓励)只是reinterpret_casts是对的吗?使用后者在寻找令人讨厌的转换时在视觉上引人注目并且易于搜索,因此推荐使用C风格转换?如果使用const_cast放弃const并写入原始const对象是未定义的,那么const_cast的目的是什么?注意:我知道Bjarne正确地谴责转换操作是不安全的,甚至达到了声明“丑陋操作应该具有丑陋语法形式的程度。“因此C++中转换运算符的冗长。所以我会尽量减少它们的使用。promise。:) 最佳答案 没有。C转换可以执行与const_cast、static_cas