jjzjj

cross-reference

全部标签

c++ - 转到特定页面后,如何将SwipeView的currentIndex设置为TabBar的currentIndex "by reference"?

我开始使用QtQuickControls2.0。我有使用C++的经验和少量的Qt经验,但我以前没有使用过QML。我有一个TabBar和一个SwipeView相互链接。我的意思是,当您在TabBar上选择一个页面时,SwipeView会转到该页面。当您从SwipeView滑动到一个页面时,TabBar会自行更新以反射(reflect)这一点。作为学习练习,我决定创建一个将用户转到第二页的按钮。问题是我似乎无法找到一种方法来做到这一点而不会弄乱TabBar和SwipeView之间的链接。下面的代码是我想出的最好的。它正确转到第二页,当我使用TabBar更改当前页面时,SwipeView仍会

c++ - std::reference_wrapper *this 周围

我有一个场景,我需要转换一个可以被*this链接的函数返回std::optional>而不是T&(原因超出了这个问题的范围)。我使用std::reference_wrapper的原因是因为std::optional不能引用,至少在C++11中不能。但是,这不起作用,因为我似乎遇到了终身问题。这是一个最小的例子:#include#includestructtest{std::reference_wrapperfoo(){val=42;return*this;}test&foo2(){val=50;return*this;}intval;};voidbar(testt){std::cout

c++ - 交叉引用和循环依赖。 header 间接包含自身

可放置的.h#include"selectable.h"classplaceable:selectable{..};可选择的.h#include"game.h"classselectable{..};游戏.h#include"placeable.h"classgame{...classplaceable*holding;...};基本上placeable.h包含selectable.h,其中包含game.h,而game.h又包含placeable.h。我能想到的唯一解决方案是将placeable*放在一个新的header中,使其成为静态/全局的,然后将这个新header包含在game.

c++ - "crosses initialization of variable"仅当初始化结合声明时

我读过thisquestion关于“跳转到案例标签”错误,但我还有一些疑问。我在Ubuntu12.04上使用g++4.7。这段代码报错:intmain(){intfoo=1;switch(foo){case1:inti=0;i++;break;case2:i++;break;}}错误是jump-to-case-label.cpp:Infunction‘intmain()’:jump-to-case-label.cpp:8:8:error:jumptocaselabel[-fpermissive]jump-to-case-label.cpp:5:9:error:crossesinitia

c++ - Google 使用 SetUpTestCase 静态变量测试 undefined reference

我正在编写一个测试用例,它将有一个SetUpTestCase()方法,尽管我收到undefinedreference链接器错误,但该方法将分配一个共享资源。classParsingEventsTest:public::testing::Test{protected:staticxmleventXml;staticvoidSetUpTestCase(){ManagedObjectManagerSingleton::GET_SINGLETON().initializeTestEnvironment(PATH_TO_FILE);eventXml=*ManagerSingleton::GET_

c++ - gtest,对 'testing::Test::~Test()' 的 undefined reference ,testing::Test::Test()

我使用apt-getinstalllibgtest-dev安装了gtest我正在尝试检查它是否有效。所以我在eclipse中编写了简单的测试代码。但是有错误,undefinedreferenceto'testing::Test::~Test()'undefinedreferenceto'testing::Test::Test()'相反,如果我将ATest类的继承更改为protected,错误就会消失,但是出现其他错误testing::Testisinaccessiblebaseof'ATest_AAA_Test'怎么了?#include#includeclassA{public:int

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