multiple-inheritance

How to create a class that “extends” two existing concrete classes

烂漫一生 提交于 2019-11-29 11:35:47
I very well know that it can be done with the help of interfaces and i have done it many times. But this time my situation is quite difference. I have class A , class B and i need to create another class C which extends both A and B because C should have boths functionality and also note that A and B are not inter related so even i cant say A may extend class B . I am quite confused what should i do right now. I know we cant change java... but at least there would be some way possible. Even the nearest may also do... please help me out. Adding more details:- Class B is a standard API while

c# multiple inheritance

China☆狼群 提交于 2019-11-29 10:47:44
I would like to achieve this in C# (Pseudocode) class A; class B : A; class C : A, B; ... A ac = (A)c; ... B bc = (B)c; Is this possible? You do not need multiple inheritance in this particular case: If class C inherits only from B , any instance of class C can be cast to both B and A ; since B already derives from A , C doesn't need to be derived from A again: class A { ... } class B : A { ... } class C : B { ... } ... C c = new C(); B bc = (B)c; // <-- will work just fine without multiple inheritance A ac = (A)c; // <-- ditto (As others have already said, if you need something akin to

How many vptr will a object of class(uses single/multiple inheritance) have?

China☆狼群 提交于 2019-11-29 10:35:42
问题 How many vptrs are usually needed for a object whose clas( child ) has single inheritance with a base class which multiple inherits base1 and base2. What is the strategy for identifying how many vptrs a object has provided it has couple of single inheritance and multiple inheritance. Though standard doesn't specify about vptrs but I just want to know how an implementation does virtual function implementation. 回答1: Why do you care? The simple answer is enough , but I guess you want something

CodeIgniter Extending Multiple Controllers?

别说谁变了你拦得住时间么 提交于 2019-11-29 09:37:56
问题 Can't find a way to do this, possibly because there is another way to do this? Some of my controllers extend AdminLayout and some of them extend ModLayout but I also need these pages to extend a LoggedIn Controller. class Profile extends AdminLayout, LoggedIn { However looking into there is no way to do this nicely. Is there a workaround? 回答1: Assuming that you are using Codeigniter 2, this can be done by putting all you extended controller classes in the same file. In /application/core

Java 8 default method inheritance

倖福魔咒の 提交于 2019-11-29 09:35:33
Let's say there are following types: public interface Base { default void sayHi(){ System.out.println("hi from base"); } } public interface Foo extends Base { @Override default void sayHi(){ System.out.println("hi from foo"); } } public interface Bar extends Base { } public class MyClass implements Foo, Bar { public static void main(String[] args) { MyClass c = new MyClass(); c.sayHi(); } } In this scenario, if main is executed, "hi from foo" is printed. Why does Foo 's implementation take precedence? Doesn't Bar inherit sayHi() from Base , since if MyClass was to only implement Bar , the Base

How to solve “Must be MarshalByRefObject” in a good but multiple-inheritance amputated language like C#?

﹥>﹥吖頭↗ 提交于 2019-11-29 09:12:54
How to solve "Must be MarshalByRefObject" in a good but multiple-inheritance amputated language like C#? The problem is very simple, in several cases you just have to inherit from this class (infrastructure requirements). It does not matter here really, which cases. So, what do you do if you've already inherited from some other class (your domain model requirements)? Btw good application frameworks, like spring.net always make sure you DON'T have to inherit from this class no matter what kind of infrastructure you need to apply to your class. I would like to know what am I getting -3 votes

Virtual multiple inheritance - final overrider

佐手、 提交于 2019-11-29 08:46:28
while trying to analyse in greater depth inheritance mechanism of C++ I stumbled upon the following example: #include<iostream> using namespace std; class Base { public: virtual void f(){ cout << "Base.f" << endl; } }; class Left : public virtual Base { }; class Right : public virtual Base{ public: virtual void f(){ cout << "Right.f" << endl; } }; class Bottom : public Left, public Right{ }; int main(int argc,char **argv) { Bottom* b = new Bottom(); b->f(); } The above, somehow, compiles and calls Right::f(). I see what might be going on in the compiler, that it understands that there is one

Input and Output Stream Pipe in Java

折月煮酒 提交于 2019-11-29 06:42:45
Does anyone have any good suggestions for creating a Pipe object in Java which is both an InputStream and and OutputStream since Java does not have multiple inheritance and both of the streams are abstract classes instead of interfaces? The underlying need is to have a single object that can be passed to things which need either an InputStream or an OutputStream to pipe output from one thread to input for another. It seems the point of this question is being missed. If I understand you correctly, you want an object that functions like an InputStream in one thread, and an OutputStream in

Multiple inheritance casting from base class to different derived class

冷暖自知 提交于 2019-11-29 05:47:15
Let's assume there is such class hierarchy: class A //base class class B //interface class C : public A, public B Then C object is created: A *object = new C(); Is it possible to cast object to B ? Important: I assume I don't know that object is C. I just know that it implements interface B No . This is not possible (direct casting from A* to B* ). Because the address of A and B are at different locations in class C . So the cast will be always unsafe and possibly you might land up in unexpected behavior . Demo . The casting should always go through class C . e.g. A* pa = new C(); B* pb =

C++ multiple inheritance order

余生长醉 提交于 2019-11-29 05:30:57
I'm trying to understand the affect of inheritance order in C++.. I looked online, but I couldn't find a clear and sufficient answer... So, for the sake of the question, assume there are 2 classes: class B and class C. Now, define: class A1 : public B, public C{ ... }; class A2 : public C, public B{ ... }; What is the difference between A1 and A2? Thanks a lot! The order of derivation is relevant only to determine the order of default initialization by constructors and cleanup by destructors. The order of derivation is not significant except as specified by the semantics of initialization by