草庐IT

local-class

全部标签

reflection - 为什么 SomeClass::class 是 KClass<SomeClass> 但 this::class 是 KClass<out SomeClass>

我想打印我的类(class)的属性值。funprint(){valcl=this::classcl.declaredMemberProperties.filter{it.visibility!=KVisibility.PRIVATE}.forEach{println("${it.name}=${it.get(this)}")}}当我尝试构建此代码时,出现编译器错误:Error:(34,40)Kotlin:Out-projectedtype'KProperty1'prohibitstheuseof'publicabstractfunget(receiver:T):Rdefinedinko

c++ - 如何在C++中实现继承并解决错误 "parent class is not accessible base of child class"?

我是C++新手。我喜欢探索C++中继承的概念。每当我尝试编译以下代码时,我都会收到错误消息:forC++includes,orinsteadofthedeprecatedheader.Todisablethiswarninguse-Wno-deprecated.D:\CPracticeFiles\Vehicle.cpp:Infunction`intmain()':D:\CPracticeFiles\Vehicle.cpp:26:error:`voidVehicle::setStationary_state(bool)'isinaccessibleD:\CPracticeFiles\Ve

inheritance - 如何让数据类在 Kotlin 中实现接口(interface)/扩展父类(super class)属性?

我有几个数据类,其中包括varid:Int?字段。我想在interface或superclass中表达这一点,并让数据类扩展它并在构造时设置此id。但是,如果我尝试这样做:interfaceB{varid:Int?}dataclassA(varid:Int):B(id)它提示我正在覆盖id字段,我是哈哈..Q:在这种情况下,如何让数据类A在构造时获取一个id,并设置该id在interface或superclass中声明? 最佳答案 确实,您不需要abstractclass然而。您可以覆盖interface属性,例如:interfac

inheritance - 如何让数据类在 Kotlin 中实现接口(interface)/扩展父类(super class)属性?

我有几个数据类,其中包括varid:Int?字段。我想在interface或superclass中表达这一点,并让数据类扩展它并在构造时设置此id。但是,如果我尝试这样做:interfaceB{varid:Int?}dataclassA(varid:Int):B(id)它提示我正在覆盖id字段,我是哈哈..Q:在这种情况下,如何让数据类A在构造时获取一个id,并设置该id在interface或superclass中声明? 最佳答案 确实,您不需要abstractclass然而。您可以覆盖interface属性,例如:interfac

c++ - 为什么我们必须做 template <class/typename> T 而不仅仅是 template T

代替templatevoidfunc(Targ){/*something*/}为什么我们做不到templatevoidfunc(Targ){/*something*/}来自cplusplus.com:Theonlydifferencebetweenbothprototypesistheuseofeitherthekeywordclassorthekeywordtypename.Itsuseisindistinct,sincebothexpressionshaveexactlythesamemeaningandbehaveexactlythesameway.对我来说,这似乎是不必要的样板

c++ - 那么现在 struct 可以有虚函数并支持继承吗?那么与 classes 有什么区别呢?信息隐藏的真正目的是什么?

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicate:WhatarethedifferencesbetweenstructandclassinC++http://www.cplusplus.com/reference/std/typeinfo/type_info/我想我的“老师”并没有告诉我很多关于C++中结构和类之间的区别。我在其他一些关于继承的问题中读到,默认情况下结构是公共(public)的...我也猜想结构没有构造函数/析构函数...那么还有哪些区别呢?它们有那么重要吗?当谈到私有(private)/protected属性/方法时,它们在运行时不可访问,

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++ - “Default member initializer needed within definition of enclosing class outside of member functions” - 我的代码格式不正确吗?

structfoo{structbar{~bar(){}//noerrorw/othisline};bar*data=nullptr;//noerrorw/othislinefoo()noexcept=default;//noerrorw/othisline};是的,我知道,还有一个题目完全相同,但有点不同的问题(涉及noexceptoperator和没有嵌套类型)。那里建议的解决方案(将foo的构造函数替换为foo()noexcept{})改变了语义,这里没有必要:这里我们有一个更好的答案(因此问题不是重复的)。编译器:AppleLLVM版本9.0.0(clang-900.0.37)

c++ - boost local_date_time 数学错了吗?

我正在使用Boost'sdatetimelibrary在我的项目中。当我发现它具有小时、天、月、年等持续时间类型时,我感到非常高兴,并且它们会根据您将它们添加到的内容更改它们的值(即添加1个月提前日期的月份部分,它不只是增加30天或类似的时间)。我认为此属性适用于天数类型,但我决定在将其投入生产之前对其进行测试...local_date_timet1(date(2010,3,14),hours(1),easternTime,false);//1amonDSTtransitiondate{CPPUNIT_ASSERT_EQUAL(greg_year(2010),t1.local_time

C++ : how do I use type_traits to determine if a class is trivial?

在C++0x中,我想确定一个类是否简单/是否具有标准布局,以便我可以使用memcpy()、memset()等...我应该如何使用type_traits实现下面的代码,这样我才能确认一个类型是微不足道的?templateboolisTrivialType(){boolisTrivial=???returnisTrivial;}注意:is_pod()限制太多:我希望我的类有简单的构造函数等......为了方便。补充:我认为std::is_standard_layout可能会给我我正在寻找的东西。1.如果我添加构造函数,它仍然返回true2.如果我添加一个虚方法,它返回false这是我需要确