草庐IT

expose_used

全部标签

c++ - "error: use of deleted function"在 move 构造函数中对 unique_ptr 调用 std::move 时

#includeclassA{public:A(){}A(constA&&rhs){a=std::move(rhs.a);}private:std::unique_ptra;};此代码无法使用g++4.8.4编译并抛出以下错误:error:useofdeletedfunction‘std::unique_ptr&std::unique_ptr::operator=(conststd::unique_ptr&)[with_Tp=int;_Dp=std::default_delete]’a=std::move(rhs.a);^我知道unique_ptr的复制构造函数和复制赋值构造函数已删除

c++ - 这个模式 : using a struct to contain a single method 有什么意义

在我们的代码中,我们有很多这种模式的情况:classouterClass{structinnerStruct{wstringoperator()(wstringvalue){//dosomethingreturnvalue;}};voiddoThing(){wstringinitialValue;wstringfinalValue=innerStruct()(initialValue);}};这样做的好处是什么:classouterClass{wstringchangeString(wstringvalue){//dosomethingreturnvalue;}voiddoThing(

在 h 文件中声明的 c++ 静态数组给出警告 'defined but not used'

我对以下内容感到好奇。我有一个在头文件中声明的简单C数组,如下所示:staticintuserCardsIndexes[INITIAL_CARDS_NUMBER]={0,1,8,9,16,17};它给了我一堆警告::'userCardsIndexes'definedbutnotused尽管我将这个文件包含到我的cpp文件中并使用了这个变量。我不明白的第二件事是当我像这样添加const说明符时:staticconstintuserCardsIndexes[INITIAL_CARDS_NUMBER]={0,1,8,9,16,17};警告消失了!谁能给我解释为什么我会收到这些警告以及为什么c

c++ - C++ using 在类中意味着什么?

在类定义中使用using是什么意思?classmyClass{public:[...]usinganotherClass::method;}; 最佳答案 该声明取消隐藏基类成员。这最常用于允许成员函数的重载。示例:classBase{public:voidmethod()const;};classDerived:publicBase{public:voidmethod(intn)const;//Withouttheusing,youwouldgetcompileerrorsond.method();usingBase::method

c++ - c++ : error: must use '.*' or '->*' to call pointer-to-member function in function 中的函数指针

代码片段如下。无法理解为什么会出现此错误。voidSipObj::check_each_field(){map::iteratormsg;stringstr;charname[20];boolres=false;sscanf(get_payload(),"%s%*s",name);LOGINFO(lc())second;res=(this).*sip_field();}}typedefbool(SipObj::*sip_field_getter)();staticmapsip_field_map;sip_field_getter是函数名的占位符 最佳答案

C++ - 错误 : expected unqualified-id before ‘using’

我有一个C++程序,当我尝试编译它时出现错误:calor.h|6|error:expectedunqualified-idbefore‘using’|这是calor类的头文件:#ifndef_CALOR_#define_CALOR_#include"gradiente.h"usingnamespacestd;classCalor:publicGradiente{public:Calor();Calor(inta);~Calor();intgetTemp();intgetMinTemp();voidsetTemp(inta);voidsetMinTemp(inta);voidmostra

c++ - "Use of plus() is ambiguous"错误

我正在尝试编写一个函数,它接受两个数字并打印出它们的和。#includeusingnamespacestd;intplus(int,int);intmain(){inta,b,result;cout>a>>b;result=plus(a,b);cout我得到的错误:useof`plus'isambiguous这是我的第一个C++程序,事实上,我在寻找错误时变得盲目。 最佳答案 要么做result=::plus(a,b);或者重命名函数。这是一个很好的教训,说明为什么usingnamespacestd不被认为是好的做法。

c++ - 使用 'using' 关键字使继承的构造函数公开

这个问题在这里已经有了答案:C++11inheritingconstructorsandaccessmodifiers(1个回答)关闭8年前。我正在尝试测试我的类的protected方法和构造函数。为此,我尝试对其进行子类化,并使用C++11using关键字将其成员重新导出为public:classFoo{protected:Foo(inti){}voidrun(){}};classTestableFoo:publicFoo{public:usingFoo::Foo;usingFoo::run;};intmain(){TestableFoofoo(7);foo.run();}但是,g+

c++ - Qt UI 测试 : How to simulate a click on a QMenuBar item using QTest?

我正在尝试模拟鼠标单击QMenuBar中的QMenu项,例如使用QTestLib框架单击“另存为”QAction。我正在WindowsXP32位和Qt5.0.2下尝试这个。有什么想法吗? 最佳答案 这个问题可能与问题所有者无关,但我想它可能对其他人有帮助。与QToolBar不同,QMenu没有方法widgetForAction。我为这种情况找到了一个简单的解决方法。尝试使用QTest::mouseClick弹出菜单,如果没有任何反应,请尝试使用QTest::keyClick(...,first_char_in_menu_tite,Q

c++ - "using"关键字在 C++ 中究竟做了什么?

这个问题在这里已经有了答案:Whatis"Argument-DependentLookup"(akaADL,or"KoenigLookup")?(4个答案)关闭6年前。我发现“using”关键字令人困惑。如果我确实使用了一个类或结构,那么就没有必要在同一命名空间中使用以该类或结构作为参数的函数。喜欢下面的代码。namespaceA{structtestData{intx;};inttestFunc(testDatadata){returndata.x;}}#include;usingA::testData;intmain(){testDatatest={1};printf("%d",t