草庐IT

references

全部标签

c++ - 为 std::unordered_map 中的 const std::reference_wrapper 重载 operator==

我不知道如何使用std::reference_wrapper将std::string引用获取到std::unordered_map中>。根据以下链接,我知道我需要重载operator==。Whycantemplateinstancesnotbededucedin`std::reference_wrapper`s?但是,我不知道如何编写operator==以使其采用conststd::reference_wrapper。如果包装器不是const,那将不是问题。使用char而不是std::string效果很好(不需要重载operator==)。代码:#include#include#inc

c++ - gtest 的 undefined reference

为什么下面的ASSERT_EQ会导致undefinedreferencetoBar::kBar错误?编译:g++a.cc-lgtest-lpthread#includeclassBar{public:staticconstsize_tkBar=0;};TEST(Basic,Basic){ASSERT_EQ(0,Bar::kBar);}intmain(intargc,char**argv){testing::InitGoogleTest(&argc,argv);returnRUN_ALL_TESTS();} 最佳答案 来自Google

C++ 初学者 : what is the point of using a variable by reference if using "const"?

我想知道这个函数声明中的逻辑:CMyException(conststd::string&Libelle=std::string(),...按引用使用变量有什么意义?通常,只要变量可能在内部被修改,您就会通过引用传递一个变量...因此,如果您使用关键字const,这意味着它永远不会被修改。这是矛盾的。谁能给我解释一下? 最佳答案 实际上引用是用来避免不必要的对象拷贝。现在,要理解为什么使用const,试试这个:std::string&x=std::string();//error编译会报错。这是因为表达式std::string()创

c++ - 对派生类的 undefined reference

编辑:与c++undefinedreferenceto`vtable有关我正在尝试做一个关于继承的项目,但我遇到了这个错误:/tmp/ccw1aT69.o:Infunction`main':main.cpp:(.text+0x15):undefinedreferenceto`Derived::Derived(int)'/tmp/ccw1aT69.o:Infunction`Derived::~Derived()':main.cpp:(.text._ZN20DerivedD2Ev[_ZN20DerivedD5Ev]+0x13):undefinedreferenceto`vtableforD

c++ - 由于对具有 std::string 的方法的 undefined reference ,链接 webrtc-native 时出错

我正在尝试构建webrtc版本62,使用以下内容1.gitcheckout-bbranch62refs/remotes/branch-heads/622.gngenout_release_62/x64/Debug--args="rtc_include_tests=falsertc_use_h264=falseuse_rtti=trueis_component_build=falseenable_iterator_debugging=falseenable_nacl=falsetarget_os=\"linux\"target_cpu=\"x64\"is_debug=true"3.nin

c++ - "Provides no initializer for reference member..."

经过一些谷歌搜索后,我找不到这个问题的答案。如何初始化它,为什么需要初始化?#include"CalculatorController.h"CalculatorController::CalculatorController(SimpleCalculator&aModel,ICalculatorView&aView){\\(thisisthebracketinformingmeoftheerror)fModel=aModel;fView=aView;}标题:#pragmaonce#include"ICalculatorView.h"#include"SimpleCalculator.h

C++ 标准 : return by copy to initialize a reference without RVO: is there any copy?

让我们考虑下一个示例:structbig_type{};//Returnbycopyautofactory(){returnbig_type{};}voidany_scope_or_function(){big_type&&lifetime_extended=factory();}假设RVO被禁止或根本不以任何方式存在,big_type()是否会或可以被复制?还是将引用直接绑定(bind)到return语句中构造的临时对象?我想确保big_type析构函数仅在any_scope_or_function结束时被调用一次。我使用C++14,以防某些行为在标准版本之间发生变化。

c++ - 链接到静态库时出现 undefined reference 错误

我正在尝试编译一个依赖于XercesXMLParser的项目.该项目可以毫无困难地针对Windows进行编译,但我在Cygwin中使用g++进行编译时遇到了一些问题。为了使用Xerces,我正在尝试针对静态库libxerces-c.a编译我的代码。但是当我这样做时,我会收到如下所示的错误:/tmp/cc2QGvMh.o:test.cpp:(.text+0x3a):undefinedreferenceto`xercesc_2_8::DOMImplementationRegistry::getDOMImplementation(unsignedshortconst*)'我已经使用ar检查了

c++ - 奇怪的编译器错误 : "undefined reference to ' main'"

谁能告诉我这是什么意思?/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crt1.o:Infunction`_start':(.text+0x18):undefinedreferenceto`main'collect2:ldreturned1exitstatusmake:***[program]Error1我的make文件如下所示:program:main.orender.oscreenwriter.og++-omain.orender.oscreenwriter.o-lSDLmain.o:main.cpprender

c++ - 继续获取 "error: use of undeclared identifier ' cout' 和错误 : reference to overloaded function could not be resolved

我正在编写一个使用许多不同函数的排序程序,你们都可以从我的声明。但是,当我尝试编译和运行我的程序时,我不断遇到这些相同的错误它们如下:error:useofundeclaredidentifier'cout';didyoumean'count'?couterror:referencetooverloadedfunctioncouldnotberesolved;didyoumeantocallit?couterror:useofundeclaredidentifier'endl';didyoumean'end'?cout我不太确定为什么会出现这些错误....我想我已经包含了我需要的一切为