草庐IT

method-reference

全部标签

c++ - 对非成员函数的 undefined reference - C++

我在头文件中有以下内容。namespacesilc{classpattern_token_map{/*Contents*/};pattern_token_map*load_from_file(constchar*);}在CPP文件中(这有适当的包含)pattern_token_map*load_from_file(constchar*filename){//Implementationgoeshere}在另一个CPP文件中。这已经包含了所有正确的内容。voidsome_method(){constchar*filename="sample.xml";pattern_token_map*

c++ - 练习 : pointers and references in C++

这是正确的吗:a)指向一个字符的指针p1:char*p1;b)指向char的常量指针p2:char*constp2;c)指向常量char的指针p3:constchar*p3;d)指向常量char的常量指针p4:constchar*constp4;e)对char的引用r1:char&r1;f)对常量char的引用r2:constchar&r2;如果有任何错误,请告知我好吗? 最佳答案 他们都是对的。我看不到任何错误:-) 关于c++-练习:pointersandreferencesinC+

c++ - 为什么隐含的 "lambda to function pointer conversion"禁止静态成员的 "by reference"捕获?

C++11标准说(或者至少,我拥有的版本——不是最终版本):Theclosuretypeforalambda-expressionwithnolambda-capturehasapublicnon-virtualnon-explicitconstconversionfunctiontopointertofunctionhavingthesameparameterandreturntypesastheclosuretype’sfunctioncalloperator.我理解为什么无法从有状态lambda中获取函数指针,因为函数指针本身不能保存任何数据。但是当捕获的对象只是一个静态成员/静

c++ - "Undefined reference"到定义的构造函数

我有一个构造函数,其签名是这样的:cpuInput(conststd::string&label);实际的构造函数使用一个引用超构造函数的初始化列表,所以它看起来像这样:cpuInput::cpuInput(conststring&label):StateMonitor::input(label){}该类可以很好地编译为目标文件。如果我将该文件与调用构造函数的驱动程序一起编译:cpuInput*cpu=newcpuInput();当然,我从g++得到一个错误:demo.cpp:15:31:error:nomatchingfunctionforcallto‘cpuInput::cpuIn

C++ : Calling a child method from parent instantiation

在我的代码中,我实现了这些类:classA{public:virtualintfun(){return0;}}classB:publicA{public:virtualintfun(){return1;}}还有这些函数:voidoperation(Aa){printf("%d\n",a.fun());}intmain(){Bb;operation(b);return0;}可以看到,B类继承了A类,并实现了虚继承方法fun()。主类调用一个以A为参数的函数,并调用fun()方法,参数为B对象。在执行时,我希望打印字符串"1",但它是"0"(即使它是传递给的B对象操作()).我需要这样做,

c++ - 是否有解决 undefined reference /未解析符号问题的通用指南?

我在工作时遇到了几个“undefinedreference”(在链接期间)和“未解析的符号”(在dlopen之后的运行时)问题。这是一个相当大的makefile系统。链接库和使用编译器标志/选项来规避这些类型的错误是否有一般规则和指南? 最佳答案 如果您使用的是MSVC:您不能通过设置标志来避免此类错误:这意味着某些单元(.cpp)没有声明标识符的定义。这肯定是由于某处缺少包含或缺少对象定义(通常是静态对象)造成的。在开发过程中,您可以遵循这些指南(来自thosearticles),以确保您的所有cpp都包含他们需要的所有heade

c++ - 理解c++代码; *datatype 和 classname::method 是什么意思?

我是C++的新手,我想了解一些代码。在数据类型前面加一个*是什么意思?为什么方法名前面是类名CAStar::LinkChildvoidCAStar::LinkChild(_asNode*node,_asNode*temp){} 最佳答案 数据类型前面的*表示变量是指向数据类型的指针,在本例中是指向节点的指针。不是将整个“节点”的拷贝传递到方法中,而是传递内存地址或指针。有关详细信息,请参阅PointersinthisC++Tutorial.方法名前面的类名说明这是定义CAStar类的一个方法。有关详细信息,请参阅Tutorialpa

c++ - 编译器首先返回 "synthesized method ‘operator=’ 此处需要”

我知道这可能是一个简单的问题,但过去一个半小时我一直在研究它,我真的迷路了。这里是编译错误:synthesizedmethod‘File&File::operator=(constFile&)’firstrequiredhere我有这段代码:voidFileManager::InitManager(){intnumberOfFile=Settings::GetSettings()->NumberOfFile()+1;for(unsignedinti=1;i_files如果在此header中定义:#pragmaonce//C++Header#include//CHeader//local

c++ - gcc编译C++代码: undefined reference to `operator new[](unsigned long long)'

有一段C++代码:#includeintmain(){intb=sizeof('a');if(b==4)printf("I'maCprogram!\n");elseprintf("I'maC++program!\n");}像这样编译:gccmain.cpp-omain它成功并给出:I'maC++program!然后在函数main的某处添加一行int*p1=newint[1000];它失败了:C:\Users\...\AppData\Local\Temp\cccJZ8kN.o:main1.cpp:(.text+0x1f):undefinedreferencetooperatornew[]

c++ - pass-by-reference & 和 * 之间的区别?

这个问题在这里已经有了答案:Passingamodifiableparametertoc++function(12个答案)关闭12个月前。按引用传递和使用C指针表示法有什么区别?voidsome_function(some_type¶m)和voidsome_function(some_type*param)谢谢