草庐IT

reference-parameters

全部标签

c++ - 对 google::protobuf::internal::empty_string_[abi:cxx11] 的 undefined reference

我正在尝试使用ProtocolBuffers2.6.1和GNUGCC5.1.0(在Ubuntu14.10上)构建简单的测试应用程序,但出现以下错误:/home/ragnar/cpp-tools/gcc-linux/bin/g++-c"/home/ragnar/cpp-projects/gprotobuf_test/main.cpp"-g-O0-Wall-o./Debug/main.cpp.o-I.-I/home/ragnar/cpp-tools/libs/linux64/protobuf/include-I./home/ragnar/cpp-tools/gcc-linux/bin/g+

C++函数参数: use a reference or a pointer (and then dereference)?

我得到了一些代码,其中一些参数是指针,然后指针被取消引用提供值(value)。我担心指针取消引用会花费周期,但是在查看之后上一篇StackOverflow文章:Howexpensiveisittodereferenceapointer?,也许没关系。这里有一些例子:boolMyFunc1(int*val1,int*val2){*val1=5;*val2=10;returntrue;}boolMyFunc2(int&val1,int&val2){val1=5;val2=10;returntrue;}就风格而言,我个人更喜欢通过引用传递,但有一个版本更好(在流程周期方面)比另一个?

C++/mysql 连接器 - 对 get_driver_instance 的 undefined reference - 已经尝试过简单的东西

是的,这个问题之前已经被问过......我已经尝试了前面答案中提到的所有内容。我的设置非常简单,所以这不应该那么难。我只想使用C++对mysql进行编程。我的源代码是从这里的“helloworld”类型示例中逐字提取的:http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html我在Ubuntu12.10上。我正在尝试:g++-Wall-ofirsttry_prog-I/usr/include/mysqlcppconn-I/usr/local/boost_1_53_0-L/us

c++ - 构造函数 : difference between defaulting and delegating a parameter

今天,我偶然发现了thesestandarddeclarationsstd::vector构造函数://untilC++14explicitvector(constAllocator&alloc=Allocator());//sinceC++14vector():vector(Allocator()){}explicitvector(constAllocator&alloc);这种变化可以在大多数标准容器中看到。一个稍微不同的例子是std::set://untilC++14explicitset(constCompare&comp=Compare(),constAllocator&al

C++ 共享库 undefined reference `FooClass::SayHello()'

我正在制作一个C++共享库,当我编译一个使用该库的主exe时,编译器会提供给我:main.cpp:(.text+0x21):undefinedreferenceto`FooClass::SayHello()'collect2:ldreturned1exitstatus库代码:fooclass.h#ifndef__FOOCLASS_H__#define__FOOCLASS_H__classFooClass{public:char*SayHello();};#endif//__FOOCLASS_H__fooclass.cpp#include"fooclass.h"char*FooClass

c++ - 奇怪的编译器错误 : Cannot convert parameter from 'int' to 'int &&'

这到底是怎么回事?我正在尝试创建一对int和一个string如果我使用“魔术值”但似乎无法传递变量,我可以创建这对.std::vector>num_text;std::stringtext="Smeg";intnum=42;//Worksfinenum_text.push_back(std::make_pair(42,std::string("Smeg")));//Cannotconvertparameter2from'std::string'to'std::string&&'num_text.push_back(std::make_pair(42,text));//Cannotcon

C++:参数传递 "passed by reference"

我理解与任何其他变量一样,参数的类型决定了参数与其参数之间的交互。我的问题是,为什么要引用参数而不是为什么不引用参数的原因是什么?为什么有些函数参数是引用而有些不是?无法理解这样做的好处,有人可以解释一下吗? 最佳答案 存在通过引用传递的能力有两个原因:修改函数参数的值为了避免出于性能原因复制对象修改参数示例voidget5and6(int*f,int*s)//usingpointers{*f=5;*s=6;}这可以用作:intf=0,s=0;get5and6(&f,&s);//f&swillnowbe5&6或voidget5and

c++ - 忽略: warning: unused parameter有什么后果

我正在处理一个C++项目,我注意到我们有许多关于未使用参数的警告。如果忽略这些警告会有什么影响? 最佳答案 带有未使用参数的函数在以下情况下可能存在真正的错误:有一个输出参数,没有被赋值或写入,导致调用者的值未定义。其中一个参数是回调函数指针,您必须调用它而忘记这样做。如果函数中有很多#ifdef,可能会发生这种情况。你声明了一个同名的局部变量,它隐藏了一个参数,随后在函数中使用了错误的值。不使用输入参数可能是无害的,但您可以通过强制转换在函数开头显式标记未使用的输入参数来减少噪音以查看有用的警告它到void(适用于C和C++):(

c++ - undefined reference

这个问题在这里已经有了答案:Whatisanundefinedreference/unresolvedexternalsymbolerrorandhowdoIfixit?(38个回答)关闭4个月前。当我为链表编译代码时,我得到了一堆undefinedreference错误。代码如下。我一直在编译这两个语句:g++test.cpp还有g++LinearNode.hLinearNode.cppLinkedList.hLinkedList.cpptest.cpp我真的不明白为什么会出现这些错误,因为我对C++中的类真的很生疏。我真的需要一些帮助。线性节点.h:#ifndefLINEARNOD

c++ - 对类构造函数的 undefined reference ,包括 .cpp 文件修复

我遇到的问题是,当我为我创建的类调用构造函数时,出现以下错误。main.cpp:20:undefinedreferenceto`StaticObject::StaticObject(Graphics*,sf::String,sf::Vector2)'这个问题可以像这样在main.cpp中为.cpp文件添加一个包含“修复”。...#include"GameObjects/StaticObject.cpp"...虽然这解决了问题,但这似乎是一个糟糕的解决方案,与我之前所说的背道而驰。有没有其他方法可以解决这个问题?我正在使用带有g++的Netbeans7.3来编码/编译这个程序。下面是相关