草庐IT

parameter-passing

全部标签

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++ 错误 : deduced conflicting types for parameter 'T' string vs const char *

因此,我正在为双端队列容器编写一个简单的模板化搜索函数。这是代码:templatevoidsearchInDequeFor(std::dequeDeque,TsearchValue){for(constauto&element:Deque){if(Deque.empty()){std::cout下面是我在main中调用函数的方式:dequemyDeque={"apple","banana","pear","blueberry"};searchInDequeFor(myDeque,"pear");这是我遇到的错误:candidatetemplateignored:deducedconfl

C++ 构造函数——通过引用传递仅适用于 const。为什么?

所以今天早些时候,我正在catch很好的旧C++,当我编译我的代码时它不工作。像一些程序员一样,我开始四处寻找,最终发现添加键盘const可以解决问题。但是,我不太喜欢黑客攻击,想知道为什么代码在添加const后运行良好。这是我在将const添加到构造函数之前的代码:#include#includeusingnamespacestd;classNames{private:string_name;string_surname;public:Names(string&name,string&surname):_name(name),_surname(surname){}stringgetN

c++ - vector 声明 "expected parameter declarator"

这个问题在这里已经有了答案:Whycan'tmemberinitializersuseparentheses?(2个答案)关闭5个月前。我在类的私有(private)成员变量中有一行代码:vectordQdt(3)在xcode中编译时,会出现错误“expectedparameterdeclarator”。我想我提供了足够的信息。我认为此声明没有任何问题。

C++ 与 git 和 CMake : How to build submodules with specific parameters?

考虑一个在git存储库中组织的C++项目。假设git存储库有一个子模块,(super)项目依赖于该子模块构建了一个库。如果(super)项目不仅依赖于库,还依赖于使用特定(CMake)参数构建的库,那么如何确保在构建(super)项目时使用这些参数构建子模块? 最佳答案 必须将构建选项(如MYLIB_WITH_SQLITE)添加到库的接口(interface)中,即在老式配置的情况下添加到MYLIB_DEFINITIONS变量中-模块,或者到INTERFACE_COMPILE_DEFINITIONS属性,如果库使用install(E

c++ - 为什么未调用的模板类成员 *parameters* 被实例化?

这个问题是对立的:Whyuncalledtemplateclassmembersaren'tinstantiated?,作者对某些模板方法未实例化感到惊讶。我遇到了相反的问题:我的部分函数在我不期望的时候被实例化了。采取以下程序:templateclassFoo;templateclassBar{templatevoidBaz(typenameFoo::Xx){}};intmain(){Barbar;}此程序编译失败并出现错误:test.cc:6:40:error:implicitinstantiationofundefinedtemplate'Foo'templatevoidBaz(

c++ - 函数调用的 "this"的评估是否以相对于参数的未指定顺序进行?

众所周知(虽然不够广泛>.puts()可以任意顺序出现,作为任意编译器选择:#includeintFunction1(){std::puts("Function1");return1;}intFunction2(){std::puts("Function2");return2;}intAdd(intx,inty){returnx+y;}intmain(){returnAdd(Function1(),Function2());}但是,这是否也适用于.左侧的this的求值,.*,->或->*运算符?换句话说,puts()下面的也是未指定的顺序吗?#includestructStruct{S

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++ - 模板特化站点报告 "too few template-parameter-lists"错误

代码某处有错误,但我不知道如何解决。它说“模板参数列表太少”。我不明白哪个是错误的。代码如下:#if!defined(VECTOR_H_INCLUDED)#defineVECTOR_H_INCLUDED#include//forsize_tnamespaceVec{classVector_base{public:explicitVector_base(){}};templateclassVector:publicVector_base{typedefVectorME;explicitVector(T,T,T);doubledot(constME&v)const;T&operator[]

c++ - template-parameter-list of template parameter 是什么意思

引用3.3.9/1中的一句话:Thedeclarativeregionofthenameofatemplateparameterofatemplatetemplate-parameteristhesmallesttemplate-parameter-listinwhichthenamewasintroduced.你能举个例子来理解上面的定义吗?我也想知道模板参数的模板参数列表是什么意思?示例会有所帮助。 最佳答案 template//thedeclarativeregionendshereclassq//hencethenamema