草庐IT

keyword-argument

全部标签

c++ - 默认参数 : can only the last argument(s) be left?

我知道可以做类似的事情:intfoo(inta=0,intb=1){returna+b;}然后在没有默认参数的情况下使用它,例如:foo();//a=0,b=1->1或将最后一个作为默认值,例如:foo(2);//a=2andb=1default->3但是我的问题是:是否可以为第一个参数(a)使用默认值并给出第二个参数(b)的值我的第一个想法是这样做(行不通!):foo(,2);//a=0defaultandb=2这个语法是否存在或者这是不可能的? 最佳答案 不,在当前语法中这是不可能的。

c++ - (SWIG C++ 到 Python)警告 301 : class keyword used, 但不是在 C++ 模式下

我正在尝试为python编译C++扩展。我创建了一个接口(interface)文件foo.i,如下所示:%modulefoo%include"typemaps.i"//Forpointerstoprimitivetypes%include"std_string.i"//std::stringmapping%applyconststd::string&{std::string*foo};//datatypescontainingstd::stringmembers%{#defineSWIG_FILE_WITH_INIT#include"../path/to/c++/header/file

C++ 模板复制构造函数,编译器说 "passing const as this argument discards qualifiers"

我正在尝试创建动态矩阵的模板类。凭借我目前对C++的了解,我设法解决了一些问题,但我被复制构造函数和重载operator=;困住了。换句话说,我无法创建对象的拷贝。在我看来这应该可行,但我的编译器friend告诉我有1个错误:错误:将“constMatrix”作为“intMatrix::getElement(int,int)[withT=int]”的“this”参数传递会丢弃此行的限定符[-fpermissive]:m[i][j]=original.getElement(i,j);当我想创建一个对象时:Matrixm=Matrix(3,3);我的模板类在这里:templateclass

c++ - (C++) 错误 : 'invalid_argument' was not declared in this scope

我正在使用EclipseC/C++和MinGW编译器。我已将标志-std=c++11添加到项目属性中C/C++Build下的MiscellaneousGCCCCompilerSettings中。我知道这可能是一件简单的事情,但我无法解决此错误。Date.h#includeusingnamespacestd;classDate{public:Date(intm=1,intd=1,inty=1900);voidsetDate(int,int,int);private:intmonth;intday;intyear;staticconstintdays[];};日期.cpp#include#

c++ - 警告 C4244 : 'argument' : conversion from 'SIZE_T' to 'DWORD' , 可能丢失数据

我需要在我的代码中有一组重载函数,但我得到了转换wanrings。这是一个测试代码:#includewindows.hvoidf(DWORDarg){...}//voidf(SIZE_Targ){}voidmain(void){DWORDdword=0;SIZE_Tsize_t=dword;f(size_t);}编译器给出警告:test.cpp(11):warningC4244:'argument':conversionfrom'SIZE_T'to'DWORD',possiblelossofdata如果我取消注释voidf(SIZE_Targ)我得到test.cpp(5):errorC

c++ - QtCreator : How do I register "override" and "final" as a keyword?

C++11(或C++0x)向C++引入了override和final关键字。很棒的东西,我们将使用它们来改进我们的代码。但是,虽然MSVisual-C++2010编译器完美地处理了关键字,但QtCreator(我选择的IDE)却完全被它们搞糊涂了。override方法被标记为错误,而且——更糟糕的是——所有代码导航功能或符号代码搜索都被完全搞砸了。:(我的问题就这么多了。我的问题如上:如何教QtCreator将override和final识别为关键字?谢谢!--罗宾PS:我使用QtCreator2.3,AFAIK的最新稳定版本。编译器为MSVC2010。 最

c++ - 嵌套命名空间 : where should default template arguments go? 中模板类的前向声明

我在嵌套命名空间中有一个模板类的前向声明namespacen1{namespacen2{templatestructA;}usingn2::A;}接着是一个定义,实际上它在不同的文件中,中间有一些东西:structX{};namespacen1{namespacen2{templatestructA{};}usingn2::A;}那么以下总是可以的:n1::n2::Aa;但是这个捷径n1::Aa;在clang中给出编译错误error:toofewtemplateargumentsforclasstemplate'A'除非我删除前向声明;g++两者都接受。clang似乎保留在第一个不包含

c++ - 错误 : argument of type char* is incompatible with parameter of type LPCWSTR

#include#includeusingnamespacestd;intmain(){char*file="d:/tester";WIN32_FIND_DATAFindFileData;HANDLEhFind;hFind=FindFirstFile(file,&FindFileData);//lineoferrorsaysargumentoftypechar*isincompatiblewithparameteroftypeLPCWSTR}我无法理解错误。错误是什么以及如何解决错误?我正在制作一个控制台应用程序,需要检查目录中是否有文件。 最佳答案

c++ - boost .python : Argument types did not match C++ signature

我在python中调用C++函数时遇到一个奇怪的问题。我公开了一个我想从中调用函数的类:class_>("MyClass",init())//....def("someFunc",&MyClass::someFunc);我得到一个std::shared_ptr来自另一个类的成员变量,该类通过.def_readonly(...)公开当我尝试调用该函数时,出现以下错误:File"pytest.py",line27,intest_funccu.someFunc("string")Boost.Python.ArgumentError:PythonargumenttypesinMyClass.s

parser.add_argument:错误:未识别的参数:true

我在Python2.7中有一个程序,该程序具有一系列代码:parser.add_argument('--skip_train',default=False,help='skiptraining',action='store_true')该代码告诉程序默认情况下进行培训。但是现在我想在没有培训的情况下实施它,因为培训已经完成。因此,我输入了提示:pythonmyprogame.py--skip_trainTrue但这给出了一个错误消息:error:unrecognizedarguments:True应该在提示命令中输入什么以实现该程序?看答案当您使用时action='store_true',您不