草庐IT

reference-parameters

全部标签

c++ - 对静态 constexpr 字符串的 undefined reference (除非它是一个指针)

这项工作:templatestructSomething{staticconstexprconstchar*str="int";};intmain(){std::cout::str但事实并非如此:templatestructSomething{staticconstexprconstcharstr[]="int";};intmain(){std::cout::strgcc-4.8说:“对Something::str的undefinedreference”。这个错误可以通过在类外定义静态成员来解决:templateconstexprconstcharSomething::name[];为

c++ - Visual Studio 2010 Arduino cpp 错误 : argument of type "char *" is incompatible with parameter of type "LPCWSTR"

我正在尝试设置一个arduinouno用于与visualstudio2010中的C++程序进行串行端口通信。我正在使用此处找到的代码:http://playground.arduino.cc/Interfacing/CPPWindows不幸的是,.cpp文件在第9行为变量“portName”提供了以下消息:错误:“char*”类型的参数与“LPCWSTR”类型的参数不兼容我不明白这个错误消息,并尝试了一些不同的方法来修复它。任何帮助将不胜感激! 最佳答案 鉴于您问题中的代码链接,问题似乎出在这里:Serial::Serial(cha

c++ - 等同于 "typename",表示从属名称确实是 'template template parameter'

我们将无法找到正确语法的部分代码缩减为最小示例。让我们假设以下定义(不用担心“为什么”;)templateclassElement{};templateclass>classClient{};templatestructTemplatedProvider{templateusingelement_template=Element;};现在,从C++11开始,我们可以使用类模板或类型别名模板来实例化Client模板。以下函数编译得很好:voidfun(){Clientclient;Client::element_template>clientBis;}但在以下情况下,当给Client的模

c++ - const_reference_type 不编译但 const value_type& 编译

#includetemplatestructref_exp{typedefTvalue_type;typedefvalue_type&reference_type;typedefconstreference_typeconst_reference_type;ref_exp(value_typedata):_data(data){}const_reference_typedata()const{return_data;}private:value_type_data;};intmain(){ref_expexp1(2);std::cout上面的代码无法编译ref.cpp:Inmember

c++ - 解决链接器错误 : undefined reference to static class members

我的代码是Arduinoish。我打开了详细编译,这样我就可以验证所有.o文件确实正确地传递给了链接器,并且它们是(下面的链接器命令)。这让我相信这是某种语法错误。谷歌搜索错误“undefinedreferencetoinfunction”会产生很多结果,答案包括“像这样将foo.o添加到您的链接器命令”等。我希望解决方案就像缺少点或->某处一样简单。我在一个文件中收到来自链接器的这一系列错误:SerialServoControl.cpp.o:Infunction`SerialServoControl::send(int,int)':SerialServoControl.cpp:31:

c++ - 对 Eclipse C++ 的 undefined reference

我已经尝试了越来越多的时间,但我得到了同样的错误。当我使用外部库时,例如我尝试使用openssl和crypto++,我收到错误:“对(函数)的undefinedreference”。我不知道为什么Eclipse会那样做,尽管#include都是正确的。我什至尝试添加来自Properties-C/C++General-Path&Symbols的路径,但什么也没有。谁能帮帮我? 最佳答案 您必须指定必须链接到可执行文件的共享库的名称。假设您使用的是GNU工具链,您可以按照以下步骤进行操作:右键单击项目,然后选择Properties进入C

c++ - 如何修复 "undefined reference"编译器错误

在以下代码中找到错误:classA{public:staticinti;voidprint(){cout我运行上面的代码,我得到了"undefinedreferenceto`A::i'"。为什么会出现此错误? 最佳答案 由于A::i是一个static成员,它必须是definedoutsideoftheclass:usingnamespacestd;classA{public:staticinti;//A::iisdeclaredhere.voidprint(){cout 关于c++-如何

c++ - 重载 << 运算符错误 C2804 : binary 'operator <<' has too many parameters

这是我的类(class):#ifndefCLOCK_H#defineCLOCK_Husingnamespacestd;classClock{//MemberVariablesprivate:inthours,minutes;voidfixTime();public://Getter&settormethods.voidsetHours(inthrs);intgetHours()const;voidsetMinutes(intmins);intgetMinutes()const;//ConstructorsClock();Clock(int);Clock(int,int);//CopyC

c++ - Visual Studio 2017 "Object reference not set to an instance of an object."的 cppcheck 插件问题

我正在尝试将cppcheck插件与visualstudio2017一起使用。但是,当我选择工具/使用cppcheck检查当前项目时,它总是说“对象引用未设置为对象的实例。”有什么建议吗?我正在使用MicrosoftVisualStudioProfessional2017,版本15.7.6CPPCheckPlugin1.3.5CMake3.12.1Windows10专业版64位谢谢。 最佳答案 对我来说,在我编辑项目并选中“EnableCodeAnalysisonBuild”后问题就解决了。然后我可以取消选中此选项,但它离开了fals

c++ - 有没有办法绕过 "returning reference to local variable"问题?

我有一个作业练习。我几乎可以肯定他们问的方式是无法解决的。但是,如果你们对下面提到的问题有任何解决方案,我很感兴趣,因为它似乎经常发生。说明不长,下面分享给大家:AmatrixS∈Rn×nisskewsymmetricifitholdsthatS(Transpose)=−S.DerivefromtheclassSquareMatrixfromthelecturetheclassSkewSymmetricMatrix.Useavectoroflengthn(n−1)/2tostorethematrixentries.Implementconstructors,typecastingand