草庐IT

constructor_arguments

全部标签

android - Gradle 同步失败 : Argument for @NotNull parameter 'aFileName' of com/intellij/openapi/util/io/FileUtil. toSystemIndependentName 不能为空

我将我的项目导入到AndroidStudio1.3.2,现在显示错误GradlesyncstartedGradlesyncfailed:Argumentfor@NotNullparameter'aFileName'ofcom/intellij/openapi/util/io/FileUtil.toSystemIndependentNamemustnotbenullGradlesynccompletedIllegalArgumentException:FailedtosetupAndroidmodulesinproject'MaterialTabs':Argumentfor@NotNul

constructor - 为什么 Kotlin 有两种类型的构造函数?

Kotlin有两种类型的构造函数,主要的和次要的。有两种类型的目的是什么?在我看来,它使代码更加复杂和不一致。如果这两种类型的构造函数都创建了一个类的对象,那么它们对一个类同样重要。同时,多个初始化器也会引入困惑并降低可读性。 最佳答案 当您需要将作为构造函数参数传递的值保存到实例的属性时,主构造函数涵盖了流行的用例。基本上,主构造函数为声明属性和从构造函数参数初始化属性提供了简写。请注意,您完全可以在没有主构造函数的情况下执行相同操作:classFoo{valbar:Barconstructor(barValue:Bar){bar

constructor - 为什么 Kotlin 有两种类型的构造函数?

Kotlin有两种类型的构造函数,主要的和次要的。有两种类型的目的是什么?在我看来,它使代码更加复杂和不一致。如果这两种类型的构造函数都创建了一个类的对象,那么它们对一个类同样重要。同时,多个初始化器也会引入困惑并降低可读性。 最佳答案 当您需要将作为构造函数参数传递的值保存到实例的属性时,主构造函数涵盖了流行的用例。基本上,主构造函数为声明属性和从构造函数参数初始化属性提供了简写。请注意,您完全可以在没有主构造函数的情况下执行相同操作:classFoo{valbar:Barconstructor(barValue:Bar){bar

constructor - 在 Kotlin 中匿名实现接口(interface)导致 "has no constructors"错误

我正在尝试在Android中使用SurfaceView来保存相机预览。文档告诉我,我需要在表面支架的surfaceCreated回调中调用startPreview。我正在尝试像这样设置回调this.surface!!.holder!!.addCallback(SurfaceHolder.Callback(){funsurfaceChanged(holder:SurfaceHolder,format:Int,width:Int,height:Int){}funsurfaceCreated(holder:SurfaceHolder){}funsurfaceDestroyed(holder:

constructor - 在 Kotlin 中匿名实现接口(interface)导致 "has no constructors"错误

我正在尝试在Android中使用SurfaceView来保存相机预览。文档告诉我,我需要在表面支架的surfaceCreated回调中调用startPreview。我正在尝试像这样设置回调this.surface!!.holder!!.addCallback(SurfaceHolder.Callback(){funsurfaceChanged(holder:SurfaceHolder,format:Int,width:Int,height:Int){}funsurfaceCreated(holder:SurfaceHolder){}funsurfaceDestroyed(holder:

c++ - Q : Template class that takes either a normal type or a template template argument

最近我设计了元类型和允许编译时类型连接的可能操作:#includetemplatetypenameT>structMetaTypeTag{};/*variabletemplatehelper*/templatetypenameT>constexprMetaTypeTagmeta_type_tag={};templatestructTypeTag{};/*comparison*/templateconstexprbooloperator==(TypeTag,TypeTag){returntrue;}templateconstexprbooloperator==(TypeTag,TypeT

c++ - 右值数据成员初始化 : Aggregate initialization vs constructor

对于下面的代码:#include#include#includeusingnamespacestd;structFoo{stringtag;Foo(stringt):tag(t){cout结果(g++7.1.0):Foo:BarFoo:Baz~Foo:Baz我们可以看到bar成功地延长了临时Foo的生命周期,但是baz没有这样做。两者有什么区别?如何正确实现Baz的构造函数?编辑:实际上VC++2017给出:Foo:Bar~Foo:BarFoo:Baz~Foo:Baz所以我猜整个事情都不可靠。 最佳答案 Baz是一个带有构造函数的类

c++ - 用已知数量的元素填充 vector : specify its size in constructor or by using reserve method?

我想通过从流中读取单个元素来创建某种复杂类型的vector。我提前知道vector大小。是在vector构造函数中指定元素个数更好,还是使用reserve方法更好?这两个哪个更好?intmyElementCount=stream.ReadInt();vectormyVector(myElementCount);for(inti=0;i或intmyElementCount=stream.ReadInt();vectormyVector;myVector.reserve(myElementCount);for(inti=0;i如果我只是创建一个intvector或其他一些简单类型呢?

c++ - 这个 'missing template arguments' C++ 错误是什么意思

啊,C++模板...ThecodeIsee,makessensetome,butGCC...itdisagrees.以下代码按预期编译和运行,但如果您取消注释#define,则会出现我不理解的错误。符号iterator仍然只有一件事可以引用:父类(superclass)中的typedef。所以我想我有两个问题:1.错误是什么意思?2.修复它们的最佳方法是什么。#include#include#includeusingnamespacestd;//#defineWITH_TEMPLATE1#ifdefWITH_TEMPLATEtemplatestructMyClass:publicmap

c++ - (void*) 和 (void(*)(argument type)) cast 之间有什么区别?

这个问题在这里已经有了答案:WhyarefunctionpointersanddatapointersincompatibleinC/C++?(14个答案)关闭7年前。voidfuncPtr(inta);intmain(){intk=1;void(*funcPtr2)(int);funcPtr2=(void*)(funcPtr);//funcPtr2=(void(*)(int))(funcPtr);(*funcPtr2)(k);return0;}voidfuncPtr(inta){printf("%d",a);}函数指针类型转换中(void*)和(void(*)(argumenttyp