草庐IT

ctor-initialiser

全部标签

php - 在 PHP 中声明一个类的 ctor 'final' 是不好的做法吗?

如果我有一个由许多其他类扩展的父类,并且我想确保父类的构造函数始终运行,声明构造函数final是不是一个坏主意>?我正在考虑做这样的事情:classParentClass{publicfinalfunction__construct(){//parentclassinitialization...$this->construct();}protectedfunctioninit(){echo'constructing';}}classChildClassextendsParentClass{protectedfunctioninit(){//childclassinitializati

php - laravel PDO::ATTR_STATEMENT_CLASS 需要格式 array(classname, array(ctor_args));类名必须是指定现有类的字符串

我正在做一个laravel项目,然后我使用composer安装了一个新包,我发现了这个错误PDO::ATTR_STATEMENT_CLASS需要格式array(classname,array(ctor_args));类名必须是指定现有类的字符串我试着:-恢复到之前在git上的提交删除供应商文件夹和composer.lock并重新安装都没有结果 最佳答案 这里遇到了同样的问题。到目前为止,降级到composerrequiredoctrine/dbal=2.6.3就可以了。 关于php-la

java - 如何解决 Android Firebase 错误 "Default FirebaseApp is not initialised in this process"?

我正在使用FirebaseAuth通过电子邮件和密码进行用户注册,并且我已经在我的项目中添加了插件和依赖项。MainActivity.javapublicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{EditTexted_email,ed_pass;Buttonbut_login;ProgressDialogprogressDialog;FirebaseAuthfirebaseAuth;Contextcontext;@OverrideprotectedvoidonCreate(Bundle

c++ - std::move( ) 在没有 move-ctor 的情况下调用 copy-ctor。为什么以及如何预防?

我想知道是否有一种安全编程实践可以在这种微妙的行为发生时提醒编码人员,或者更好的是,首先避免这种行为。structA的用户可能没有意识到没有move构造函数。在他们尝试调用不存在的ctor时,他们既没有收到编译器警告,也没有收到任何运行时指示调用了复制ctor。下面的答案解释了发生的转换,但我看不出这是一件好事的任何理由。如果缺少以const引用作为参数的构造函数,则会出现编译时错误,而不仅仅是解析为非常量引用版本。那么,当类中没有实现move语义时,为什么尝试使用move语义不会导致编译时错误?有没有办法通过一些编译时选项避免这种行为,或者至少有一种在运行时检测它的方法?在move之

c++ - ctors 和 setter 参数的命名约定

对于那些没有像m_foo或foo_这样的特殊符号命名成员变量的人,您如何为您的ctors和setter命名参数?到目前为止我尝试过的一些选项...Obj(intfoo):foo(foo){}voidset_foo(intfoo){this->foo=foo;}Obj(int_foo):foo(_foo){}voidset_foo(int_foo){foo=_foo;}Obj(inta_foo):foo(a_foo){}//afor"argument"voidset_foo(inta_foo){foo=a_foo;}Obj(intinit_foo):foo(init_foo){}void

c++ - 在 ctor 的初始化列表中使用算术是否稳定?

在隐式赋值期间在类的ctor初始化列表中使用这样的东西是否稳定(没有运算符被重载):classC{public:C(int_var):var(_var),i(var*var){}private:intvar;inti;};我得到了一些错误的结果,这是为什么? 最佳答案 是的。你可能想摆脱初始化顺序依赖,然后写:C(int_var):var(_var),i(_var*_var)基本上,通过使i依赖于var,您必须确保var在类中的i之前声明。同样,您可以在C中初始化在父类中定义(和初始化)的内容,因为父类将在C之前构造。最佳实践要求您

c++ - 为什么 vector 的 move ctor 不推导出 noexcept()?

为什么要为std::vectormove构造函数使用自定义分配器不会推断出noexcept()来自分配器的行为?这导致封装此类vector的类无法形成可以在某些中正常move的(其他)vector秒。即使基础类型满足必要的要求(MoveInsertable和DefaultInsertable)。 最佳答案 我假设“使用自定义分配器为std::vectormove构造函数”是指分配器扩展的move构造函数,即这个构造函数:vector(vector&&v,constallocator_type&a);主要原因是如果v.get_allo

c++ - 使用 move ctor 的 constexpr 对象的 constexpr 数组

我有一个带有constexpr值构造函数的类,但没有复制或移动构造函数classC{public:constexprC(int){}C(constC&)=delete;C&operator=(constC&)=delete;};intmain(){constexprCarr[]={1,2};}我发现这段代码不起作用,因为它实际上是在尝试使用C的移动构造函数而不是值构造函数来就地构造。一个问题是我希望此对象不可移动(出于测试目的),但我想“好吧,好吧,我将添加一个移动构造函数。”classC{public:constexprC(int){}C(constC&)=delete;C&oper

c++ - 当其他构造函数存在时,为什么 "ctor() = default"会改变行为?

为什么structwrapper{explicitwrapper(void*);wrapper()=default;intv;};intmain(){returnwrapper().v;}//YoushouldrunthisinDebugmode返回0xCCCCCCCC,而structwrapper{wrapper()=default;intv;};intmain(){returnwrapper().v;}和structwrapper{intv;};intmain(){returnwrapper().v;}都返回0? 最佳答案 在值

swift - Xcode 7.3, swift 2.2 : default initialiser selector (new compile-time check)

我正在将一些选择器迁移到Swift2.2,但我遇到了其中一个问题:代码:lethook=ARTRealtimePresenceQuery.testSuite_injectIntoClassMethod("init"){//DefaultinitialiserpresenceQueryWasCreated=true}现在,Xcode想帮助我进行转换,但方式不对:代码:lethook=ARTRealtimePresenceQuery.testSuite_injectIntoClassMethod(#selector(_NSEnumeratorType.init)){//Defaultini