草庐IT

constructor_arguments

全部标签

序列化异常 : can't locate argument-less serializer

我正在创建一个Kotlin多平台库;实际上我有3个模块(common、jvm和js),在我得到的类路径中:classpath"org.jetbrains.kotlin:kotlin-serialization:${versions.kotlin}"在我的模块中我得到了:common:"org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:${versions.kotlinSerialization}"jdk:"org.jetbrains.kotlinx:kotlinx-serialization-runtime:${ver

序列化异常 : can't locate argument-less serializer

我正在创建一个Kotlin多平台库;实际上我有3个模块(common、jvm和js),在我得到的类路径中:classpath"org.jetbrains.kotlin:kotlin-serialization:${versions.kotlin}"在我的模块中我得到了:common:"org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:${versions.kotlinSerialization}"jdk:"org.jetbrains.kotlinx:kotlinx-serialization-runtime:${ver

c++ - 提升 : dereference a template argument if it's a pointer

如果它是一个指针(或智能指针),我可以使用什么来取消引用模板参数,或者如果它不是,我可以保持原样吗?templatevoidsubf(constT&item){item.foo();}templatevoidf(constT&item){subf(magic_dereference_function(item));}Boost中的任何内容都是一个选项。 最佳答案 templateT&maybe_deref(T&x){returnx;}templateT&maybe_deref(T*x){return*x;}您必须单独为智能指针添加重

c++ - "use of class template requires template argument list"是什么意思?

我是模板的新手,所以请原谅我的幼稚问题。我在这段代码中遇到错误:templateclassa{public:inti;a(t&ii):i(ii){}};intmain(){a*a1(newa(3));cout编译错误:'a':使用类模板需要模板参数列表'a':类没有构造函数 最佳答案 使用a*a1(newa(3));^^^^^^^^^如果你想让你的模板参数被自动推导,你可以使用一个辅助函数:templatea*createA(constT&arg)//pleaseaddconsttoyourctor,too.{returnnewa(

C++ 继承 : Calling Base Class Constructor In Header

假设类Child是类Parent的派生类。在一个五文件程序中,我如何在Child.h中指定我想调用Parent的构造函数?我认为header中的以下内容不合法:Child(intParam,intParamTwo):Parent(Param);在这种情况下,Child.cpp的构造函数语法应该是什么样的? 最佳答案 在Child.h中,您只需声明:Child(intParam,intParamTwo);在Child.cpp中,您将拥有:Child::Child(intParam,intParamTwo):Parent(Param){

c++ - 默认模板参数 : Why does the compiler complain about not specifying template argument?

我有这个代码:structA{};templatestructB{voidfoo(){}};Bb;//Error:missingtemplateargumentsbefore'b'//Error:expected';'before'b'//Moreerrorsb.foo()如果我将foo()作为具有相同模板“签名”的模板函数,编译器不会提示没有指定模板参数:structA{};structB{templatevoidfoo(){}};Bb;//OKb.foo()那么为什么我需要为带有默认参数的模板类指定参数,而不是为模板函数指定参数呢?我是否遗漏了一些微妙之处?原因肯定是因为模板参数推

constructor - 如何在 Kotlin 的构造函数 block 之外访问辅助构造函数参数

我是Kotlin的新手,正在学习可用的教程。但是现在我似乎对辅助构造函数有疑问:在主构造函数中声明的参数可以在函数中访问,但是当我尝试使用辅助构造函数中的参数执行此操作时,出现错误:未解析的引用:nbr代码:classTest(_name:String){valname:String=_nameconstructor(_name:String,_nbr:Int):this(_name){valnbr:Int=_nbr}funprintNameAndNumber(){println("Name:$name")println("Number:$nbr")}}我很清楚我做错了什么,但谁能告诉

constructor - 如何在 Kotlin 的构造函数 block 之外访问辅助构造函数参数

我是Kotlin的新手,正在学习可用的教程。但是现在我似乎对辅助构造函数有疑问:在主构造函数中声明的参数可以在函数中访问,但是当我尝试使用辅助构造函数中的参数执行此操作时,出现错误:未解析的引用:nbr代码:classTest(_name:String){valname:String=_nameconstructor(_name:String,_nbr:Int):this(_name){valnbr:Int=_nbr}funprintNameAndNumber(){println("Name:$name")println("Number:$nbr")}}我很清楚我做错了什么,但谁能告诉

java - "projections are not allowed for immediate arguments of a supertype"Kotlin Android Studio

当我将Java转换为Kotlin时出现此错误:JavapublicclassHeaderTabextendsExpandableGroup{privateStringheader;publicHeaderTab(Stringtitle,Listitems){super(title,items);}}KotlinclassHeaderTab(title:String,items:List):ExpandableGroup(title,items){privatevalheader:String?=null}AndroidStudio是这样说的:projectionsarenotallow

java - "projections are not allowed for immediate arguments of a supertype"Kotlin Android Studio

当我将Java转换为Kotlin时出现此错误:JavapublicclassHeaderTabextendsExpandableGroup{privateStringheader;publicHeaderTab(Stringtitle,Listitems){super(title,items);}}KotlinclassHeaderTab(title:String,items:List):ExpandableGroup(title,items){privatevalheader:String?=null}AndroidStudio是这样说的:projectionsarenotallow