jjzjj

initialization

全部标签

c++ - 使用 std::initializer_list 的显式构造函数和初始化

classP{public:explicitP(inta,intb,intc){std::cout我认为{77,5,42}具有std::initialization_list的隐式类型.如果是这种情况,是什么原因导致变量z的构建失败?? 最佳答案 Ithink{77,5,42}hastheimplicittypeofstd::initialization_list{77,5,42}本身没有类型。如果你写autox={77,5,42}然后x类型为initializer_list.您的示例类型P有一个明确的构造函数。实际上,这意味着您必

论文阅读:A Rotation-Translation-Decoupled Solution for Robust and Efficient VI Initialization

前言这是一篇发表在CVPR2023上的文章,ARotation-Translation-DecoupledSolutionforRobustandEfficientVisual-InertialInitialization,深蓝学院还有作者对这项工作的介绍:VIO初始化探究:旋转平移解耦的高效鲁棒初始化-深蓝学院-专注人工智能与自动驾驶的学习平台https://www.shenlanxueyuan.com/open/course/185/lesson/169/liveToVideoPreview这篇文章的主要工作,是提出了一种新的视觉-惯性里程计(VIO)初始化方法,该方法将旋转和平移估计解耦

c++ - 为派生类 move 构造函数

我有2个类:templateclassbase{Tt;public:base(base&&b):t(std::move(b.t)){}};templateclassderived:protectedbase{T2t2;public:derived(derived&&d):base(std::move(d)),t2(std::move(d.t2)){}};我在derivedmove-constructor中move整个d对象来初始化base部分和d变得无效,但我仍然需要它来使用它作为t2初始化的一部分有可能做这样的事情吗? 最佳答案

c++ - 这里保证静态初始化吗?

看这段代码:structFoo{void*ptr;constexprFoo():ptr(nullptr){}};Foof;是否保证f会被静态初始化?Clang在这里使用静态初始化,但是MSVCdoesn't. 最佳答案 是的,标准说f将被常量初始化:[basic.start.init]/2:Aconstantinitializerforanobjectoisanexpressionthatisaconstantexpression,exceptthatitmayalsoinvokeconstexprconstructorsforoa

c++ - 使用 std::initializer_list 构造函数而不产生歧义?

我有一个类叫做Shape,它可以从任何可迭代对象和一个名为Array的类中初始化,其中只包含一个Shape.但是,当我尝试初始化Array时,我遇到了无法解释的编译错误。:classShape{public:templateShape(Iteratorfirst,Iteratorlast):m_shape(first,last){}templateShape(constIterable&shape):Shape(shape.begin(),shape.end()){}templateShape(std::initializer_listshape):Shape(shape.begin(

c++ - 静态内联变量是否需要在main之前初始化?

如果我有以下A.h文件(仅header):#pragmaoncestructA{staticinlinestructInitializer{Initializer(){std::cout#include"A.h"(来自另一个header,将包含在main.cpp中)是否足够,所以Initializer::Initializer()之前被调用main()?我读到标准要求仅在使用前使用动态初始化来初始化静态变量。Itisimplementation-definedwhetherornotthedynamicinitialization(8.5,9.4,12.1,12.6.1)ofanobj

c++ - 将整数类型转换为枚举 : functional cast vs initialization

假设有一个这样的枚举:enumfoo:int{first,second}然后我使用它如下:foof(1);//error:cannotinitializeavariableoftype'foo'withanrvalueoftype'int'foof=foo(1);//OK!我想知道这两者有什么区别?我知道第二个版本可以看作是函数式转换,但为什么这会有什么不同?例如,如果我这样做:classBar{};Barb=Bar(1);//nomatchingconversionforfunctional-stylecastfrom'int'to'Bar'我显然得到了一个有意义的错误。因此,这让我

c++ - 模块 : AHBot (no matching constructor for initialization of 'WorldSession' )

基本上我遇到了这个错误,没有匹配的构造函数来初始化“WorldSession”WorldSession_session(AHBplayerAccount,NULL,SEC_PLAYER,sWorld->getIntConfig(CONFIG_EXPANSION),0,LOCALE_zhCN,0,false,false);^/home/djboxer/Projects/azerothcore/src/server/game/Server/WorldSession.h:188:9:note:candidateconstructornotviable:requires10arguments,

c++ - 是否可以用 lambda 初始化变量(当复制 ctor 被删除时)?

我有以下代码:structA{//现场观看:http://coliru.stacked-crooked.com/a/a5c5912bd79053c3编译时出现如下错误:g++-std=c++17-O2-Wall-pedantic-pthreadmain.cpp&&./a.outmain.cpp:Inlambdafunction:main.cpp:12:12:error:useofdeletedfunction'A::A(constA&)'returnres;^~~main.cpp:4:3:note:declaredhereA(constA&)=delete;^我知道我可以将其包装在另一

c++ - 复杂层次结构中的统一初始化语法?

我正在使用GCC4.4.5。这是我的问题的重现:#includeclassTest{public:Test(inta,intb=42):m_a(a),m_b(b){}private:intm_a;intm_b;};typedefstd::vectorTestList;classTestMaster{public:TestMaster(TestListtests=TestList()):m_tests(tests){}private:TestListm_tests;};现在,这有效:intmain(){TestListtest_list={15,22,38};return0;}但这不能编