multiple-inheritance

Swift does not support multiple inheritance, How could be achieved?

一笑奈何 提交于 2021-02-07 09:26:42
问题 The following code: class City { var cityId : String? var cityName : String? } class Town { var townid : String? var townName : String? } class Address : City , Town { var house : String? var street: String? } Generates a compile-time error: Address.swift:38:24: Multiple inheritance from classes 'City' and 'Town' How can I solve his kind of problem? What approach to follow? 回答1: It seems you are overthinking things. Instead of inheritance, try to use more composition. An address should not

Why won't the C++ compiler disambiguate between an inherited public and an inherited private method with the same name?

99封情书 提交于 2021-02-04 15:34:42
问题 I'm confused as to why the C++ compiler won't accept this: class Foo { private: void Baz() { } }; class Bar { public: void Baz() { }; class FooBar : public Foo, public Bar { }; void main() { FooBar fb; fb.Baz(); } The error gcc gives is: request for member ‘Baz’ is ambiguous candidates are: void Bar::Baz() void Foo::Baz() but isn't it obvious that I want Bar::Baz(), since Foo::Baz() is private? Why won't the compiler disambiguate here? 回答1: Name resolution works in two stages. First the name

Iterate over class inheritances in C++

元气小坏坏 提交于 2021-01-28 14:02:08
问题 Assume I have a some classes architecture (the number of the classes is growing up during the development time), that each class inherit from N classes with the same basic interface. What is the best way (if possible) to create a base function (in the base class OR in the derived class) that will iterate over the inheritances? Target: Avoid developers mistakes and make sure we won't forget to call all the base functions from all of the inheritances & make the code more clear to read and

Move constructors and multiple inheritance

偶尔善良 提交于 2021-01-21 06:29:49
问题 Synopsis How can I safely design a move constructor when a class uses multiple inheritance? Details Consider the following scenario: struct T { }; struct U { }; struct X : public T, public U { X(X&& other) : T(std::move(other)) , U(std::move(other)) // already moved?! { } }; Is there a way to move-construct both T and U safely? 回答1: tl;dr : the code in the question is ok. The code above is fine, because std::move itself doesn't actually change other in any way, it just does a cast to make

Using parameter that implements multiple interfaces pre-generics

喜夏-厌秋 提交于 2020-08-03 12:10:05
问题 Suppose I have these interfaces: public interface I1 { void foo(); } public interface I2 { void bar(); } and the classes: public class A extends AParent implements I1, I2 { // code for foo and bar methods here } public class B extends BParent implements I1, I2 { // code for foo and bar methods here } public class C extends CParent implements I1 { // code for foo method here } Now, with generics I can have a method like: public <T extends I1 & I2> void method(T param) { param.foo(); param.bar(