草庐IT

reference-type

全部标签

C++ 后递增 : objects vs primitive types

我们不能对右值使用预增量:inti=0;intj=++i++;//Compileerror:lvaluerequired如果我们定义一个类:classA{public:A&operator++(){return*this;}Aoperator++(int){Atemp(*this);returntemp;}};然后我们可以编译:Ai;Aj=++i++;A对象和int数据类型有什么区别j=++i++;用A编译而不用int编译? 最佳答案 发生这种情况是因为当重载运算符被定义为成员函数时,它们遵循一些与调用成员函数更相关的语义,而不是内

C++ : has_trivial_X type traits

boost库,似乎是即将推出的C++0x标准,定义了各种类型特征模板,以区分具有平凡构造函数、复制构造函数、赋值或析构函数的对象与不具有平凡构造函数的对象。其最重要的用途之一是优化某些类型的算法,例如通过使用memcpy。但是,我不明白所有各种has_trivial_X模板之间真正的实际区别。C++标准只定义了我们在这里关注的两大类类型:POD和非POD。如果一个类型具有已定义的构造函数、复制构造函数、赋值运算符或析构函数,则该类型是非POD。换句话说,任何不是内置类型或内置类型的C结构的东西都不是POD。那么区分has_trivial_assign和has_trivial_const

【OpenCV】undefined reference to `cv::dnn::dnn4_v20191202::Net::~Net()‘

Linux环境下使用opencv的dnn模块调用yolov4遇到的坑(纯CPU)1.改CMakeList.txt向CMakeLists.txt中的find_package(OpenCV4REQUIREDopencv_coreopencv_imgprocopencv_highguiopencv_calib3dopencv_videoioopencv_imgcodecs)添加opencv_dnn,即改成find_package(OpenCV4REQUIREDopencv_coreopencv_imgprocopencv_highguiopencv_calib3dopencv_videoioopen

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++ - G++ 4.4.7 中的 "names the constructor, not the type"

我有以下简单的C++代码:#includeclassA{public:A(inty):x(y){}A&operator=(constA&rhs);intx;};A::A&A::operator=(constA&rhs){this->x=rhs.x;return*this;}intmain(int,char**){Aa1(5);Aa2(4);printf("a2.x==%d\n",a2.x);a2=a1;printf("a2.x==%d\n",a2.x);return0;}第11行,A的operator=()函数的定义所在,格式不正确......或者,至少,我相信是这样。正如预期的那样,

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

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

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-