multiple-inheritance

When using multiple inheritance, why is this qualified name ambiguous?

会有一股神秘感。 提交于 2021-02-18 06:06:21
问题 I'm trying to access the member variable x in struct Top using a Bottom object. The code is the following: #include <cstdio> struct Top { public: int x = 1; }; struct Left : public Top { int x = 2; }; struct Right : public Top { int x = 3; }; struct Bottom : public Left, public Right { int x = 4; }; int main() { Bottom b; std::printf("value: %d\n", b.Left::Top::x); return 0; } This gives the following error using gcc 4.8: main.cpp: In function 'int main()': main.cpp:27:45: error: 'Top' is an

When using multiple inheritance, why is this qualified name ambiguous?

混江龙づ霸主 提交于 2021-02-18 06:05:32
问题 I'm trying to access the member variable x in struct Top using a Bottom object. The code is the following: #include <cstdio> struct Top { public: int x = 1; }; struct Left : public Top { int x = 2; }; struct Right : public Top { int x = 3; }; struct Bottom : public Left, public Right { int x = 4; }; int main() { Bottom b; std::printf("value: %d\n", b.Left::Top::x); return 0; } This gives the following error using gcc 4.8: main.cpp: In function 'int main()': main.cpp:27:45: error: 'Top' is an

When using multiple inheritance, why is this qualified name ambiguous?

Deadly 提交于 2021-02-18 06:05:13
问题 I'm trying to access the member variable x in struct Top using a Bottom object. The code is the following: #include <cstdio> struct Top { public: int x = 1; }; struct Left : public Top { int x = 2; }; struct Right : public Top { int x = 3; }; struct Bottom : public Left, public Right { int x = 4; }; int main() { Bottom b; std::printf("value: %d\n", b.Left::Top::x); return 0; } This gives the following error using gcc 4.8: main.cpp: In function 'int main()': main.cpp:27:45: error: 'Top' is an

C# extension method as an interface implementation

懵懂的女人 提交于 2021-02-17 21:10:16
问题 I was wondering if a C# extension method of some class could act as an implementation of interface? What do I have: An iterface: public interface IEventHandler { void Notify(SEvent ev, IEventEmmiter source); } A class that implements it: class Sim : IEventHandler { /*public void Notify(SEvent ev, IEventEmmiter source) { Console.WriteLine("Got notified: " + ev.Name); }*/ } And a class that contains the extension method: public static class ReflectiveEventDispatcher { public static void Notify

C# extension method as an interface implementation

随声附和 提交于 2021-02-17 21:06:10
问题 I was wondering if a C# extension method of some class could act as an implementation of interface? What do I have: An iterface: public interface IEventHandler { void Notify(SEvent ev, IEventEmmiter source); } A class that implements it: class Sim : IEventHandler { /*public void Notify(SEvent ev, IEventEmmiter source) { Console.WriteLine("Got notified: " + ev.Name); }*/ } And a class that contains the extension method: public static class ReflectiveEventDispatcher { public static void Notify

Scala Traits and Inheritance

大兔子大兔子 提交于 2021-02-11 13:37:55
问题 I have my Scala classes structured as below: trait ActualClass extends ParentClass { override def method1(inputStr:String):String = { "actual "+ inputStr } def execute():String = { this.method1("test") } } trait WithClass extends ParentClass { override def method1(inputStr:String):String = { "with "+ inputStr } } class ParentClass { def method1(inputStr:String):String = { "parent "+ inputStr } } object TestClass extends App{ val actualClass = new ActualClass with WithClass { } println

Ambiguous multiple inheritance of template classes

若如初见. 提交于 2021-02-08 12:32:14
问题 I've got a real situation which can be summarized in the following example: template< typename ListenerType > struct Notifier { void add_listener( ListenerType& ){} }; struct TimeListener{ }; struct SpaceListener{ }; struct A : public Notifier< TimeListener > , public Notifier< SpaceListener > { }; struct B : TimeListener{ }; int main() { A a; B b; a.add_listener( b ); // why is ambiguous? return 0; } Why is not obvious to the compiler that B is a TimeListener , and therefore the only

Python 3.1: C3 method resolution order

本小妞迷上赌 提交于 2021-02-07 19:26:12
问题 A very simple case of diamond-type inheritance: class Root: def f(self): print('Root') class A(Root): pass class B(Root): def f(self): print('B') class AB(A, B): pass AB().f() According to Python 3.1.2 documentation: For most purposes, in the simplest cases, you can think of the search for attributes inherited from a parent class as depth-first, left-to-right, not searching twice in the same class where there is an overlap in the hierarchy. Hence, I expect my example to resolve in the order:

Python 3.1: C3 method resolution order

ぃ、小莉子 提交于 2021-02-07 19:25:22
问题 A very simple case of diamond-type inheritance: class Root: def f(self): print('Root') class A(Root): pass class B(Root): def f(self): print('B') class AB(A, B): pass AB().f() According to Python 3.1.2 documentation: For most purposes, in the simplest cases, you can think of the search for attributes inherited from a parent class as depth-first, left-to-right, not searching twice in the same class where there is an overlap in the hierarchy. Hence, I expect my example to resolve in the order:

Scope operator for base class in super multiple non-virtual inheritance

五迷三道 提交于 2021-02-07 14:22:21
问题 Consider this (completely non-nonsensical, but perfectly valid) class inheritance: struct Area { int size; }; struct Pattern { int size; }; struct R : Area, Pattern {}; struct C : Area, Pattern {}; struct X: R , C {}; Let's see a graph of this great hierarchy: Area Pattern |\ /| | \/ | | /\ | |/ \| R C \ / \/ X Now, if I am not mistaken, X should have 4 size members. How to refer to them using the scope operator? The obvious solution doesn't work: X x; x.R::Area::size = 24; clang error: 23 :