base-class

kotlin, how to simplify passing parameters to base class constructor?

前提是你 提交于 2021-02-07 18:17:27
问题 We have a package that we are looking to convert to kotlin from python in order to then be able to migrate systems using that package. Within the package there are a set of classes that are all variants, or 'flavours' of a common base class. Most of the code is in the base class which has a significant number of optional parameters. So consider: open class BaseTree(val height:Int=10,val roots:Boolean=true, //...... lots more!! class FruitTree(val fruitSize, height:Int=10, roots:Boolean=true,

kotlin, how to simplify passing parameters to base class constructor?

☆樱花仙子☆ 提交于 2021-02-07 18:16:59
问题 We have a package that we are looking to convert to kotlin from python in order to then be able to migrate systems using that package. Within the package there are a set of classes that are all variants, or 'flavours' of a common base class. Most of the code is in the base class which has a significant number of optional parameters. So consider: open class BaseTree(val height:Int=10,val roots:Boolean=true, //...... lots more!! class FruitTree(val fruitSize, height:Int=10, roots:Boolean=true,

kotlin, how to simplify passing parameters to base class constructor?

我与影子孤独终老i 提交于 2021-02-07 18:15:52
问题 We have a package that we are looking to convert to kotlin from python in order to then be able to migrate systems using that package. Within the package there are a set of classes that are all variants, or 'flavours' of a common base class. Most of the code is in the base class which has a significant number of optional parameters. So consider: open class BaseTree(val height:Int=10,val roots:Boolean=true, //...... lots more!! class FruitTree(val fruitSize, height:Int=10, roots:Boolean=true,

copy & swap in base and derived class

倖福魔咒の 提交于 2021-02-07 03:15:59
问题 I recently read about copy & swap and am now trying to implement the ctors in a base and derived class. I have the four constructors in both my base and derived class, however I am unsure how to implement the assignment operator of the derived class. explicit Base(int i) : m_i{i} {} Base(const Base & other) : m_i{other.m_i} Base(Base && other) : Base(0) { swap(*this, other); } Base & operator=(Base other) { swap(*this, other); return *this; } friend void swap(Base & a, Base & b) noexcept {

copy & swap in base and derived class

南楼画角 提交于 2021-02-07 03:14:39
问题 I recently read about copy & swap and am now trying to implement the ctors in a base and derived class. I have the four constructors in both my base and derived class, however I am unsure how to implement the assignment operator of the derived class. explicit Base(int i) : m_i{i} {} Base(const Base & other) : m_i{other.m_i} Base(Base && other) : Base(0) { swap(*this, other); } Base & operator=(Base other) { swap(*this, other); return *this; } friend void swap(Base & a, Base & b) noexcept {

copy & swap in base and derived class

自闭症网瘾萝莉.ら 提交于 2021-02-07 03:11:18
问题 I recently read about copy & swap and am now trying to implement the ctors in a base and derived class. I have the four constructors in both my base and derived class, however I am unsure how to implement the assignment operator of the derived class. explicit Base(int i) : m_i{i} {} Base(const Base & other) : m_i{other.m_i} Base(Base && other) : Base(0) { swap(*this, other); } Base & operator=(Base other) { swap(*this, other); return *this; } friend void swap(Base & a, Base & b) noexcept {

copy & swap in base and derived class

无人久伴 提交于 2021-02-07 03:07:51
问题 I recently read about copy & swap and am now trying to implement the ctors in a base and derived class. I have the four constructors in both my base and derived class, however I am unsure how to implement the assignment operator of the derived class. explicit Base(int i) : m_i{i} {} Base(const Base & other) : m_i{other.m_i} Base(Base && other) : Base(0) { swap(*this, other); } Base & operator=(Base other) { swap(*this, other); return *this; } friend void swap(Base & a, Base & b) noexcept {

C++ array of base class which has instances of derived classes stored in the elements of the array

℡╲_俬逩灬. 提交于 2021-02-05 07:48:08
问题 I am creating an application that allows a user to define dimensions for different shapes and returns the area to the user using the dimensions they specified. My base class is Shape. Derived classes are Triangle, Circle, Square and Rectangle. I have created an array of Shape in the hope of creating and storing instances of any of the derived classes in the array during runtime. Shape** shape = new Shape*[TOTAL_SHAPES]; shape[i] = new Circle(radius); I have managed this, however I am unable

C++ array of base class which has instances of derived classes stored in the elements of the array

雨燕双飞 提交于 2021-02-05 07:48:06
问题 I am creating an application that allows a user to define dimensions for different shapes and returns the area to the user using the dimensions they specified. My base class is Shape. Derived classes are Triangle, Circle, Square and Rectangle. I have created an array of Shape in the hope of creating and storing instances of any of the derived classes in the array during runtime. Shape** shape = new Shape*[TOTAL_SHAPES]; shape[i] = new Circle(radius); I have managed this, however I am unable

conversion to inaccessible base class is not allowed [duplicate]

蹲街弑〆低调 提交于 2021-01-21 14:44:28
问题 This question already has answers here : C++ inheritance - inaccessible base? (2 answers) Closed 3 years ago . I define a class B1 and a derived class D1 at first. Then I want to define a reference to B1 and initialize that to the D1 object I just defined. Here comes the error, saying that "conversion to inaccessible base class 'B1' is not allowed", which I don't know why. #include "std_lib_facilities.h" class B1 { public: virtual void vf() { cout << "B1::vf()\n"; }; void f() { cout << "B1::f