multiple-inheritance

Why does multiple inheritance increase the size of the object despite the bases being empty?

半腔热情 提交于 2019-12-01 13:54:06
问题 Given this code: #include <iostream> struct A { }; struct B { }; struct C { }; struct E : A { int field; }; struct F : A, B { int field; }; struct G : A, B, C { int field; }; int main() { std::cout << _MSC_VER << std::endl; std::cout << sizeof(E) << std::endl; std::cout << sizeof(F) << std::endl; std::cout << sizeof(G) << std::endl; int o; std::cin >> o; return 0; } I am given the following output: 1900 4 8 8 Why would F and G have sizes of 8 even though their bases are empty? And why would

more c++ multiple inheritance fun [duplicate]

£可爱£侵袭症+ 提交于 2019-12-01 13:34:36
Possible Duplicate: C++ pointer multi-inheritance fun. (Follow up on: C++ pointer multi-inheritance fun ) I'm writing some code involving inheritance from a basic ref-counting pointer class; and some intricacies of C++ popped up. I've reduced it as follows: Suppose I have: class A{int x, y;}; class B{int xx, yy;}; class C: public A, public B {int z;}; C c; C* pc = &c; B* pb = &c; A* pa = &c; // does pa point to a valid A object? // does pb point to a valid B object? // does pa == pb ? Furthermore, does: // pc == (C*) pa ? // pc == (C*) pb ? Thanks! Here, "==" means points at the same value.

Doubts in Multiple inheritance in .net

本小妞迷上赌 提交于 2019-12-01 12:13:35
问题 We know that all the classes are inherited from the object class in .net. Say we create a class named ClassA. Then we create another class named ClassB that is inherited from ClassA. Isn't this multiple inheritance, because ClassB inherited from both Object class and ClassA? Doesn't this break the rule that C#.net doesn't support multiple inheritance? 回答1: No, you do not break the rule. Since ClassA is an object, it does not mean that you're inheriting from 2 different classes. You're

Golang: what's the point of interfaces when you have multiple inheritence [closed]

爱⌒轻易说出口 提交于 2019-12-01 11:42:11
I'm a Java programmer, learning to program in Go. So far I really like the language. A LOT more than Java. But there's one thing I'm a bit confused about. Java has interfaces because classes can inherit only from one class. Since Go allows multiple inheritance, what's the point of interfaces? Polymorphism Interfaces enable functions to have a 'placeholder' parameter which can take different structs as an argument. For example, if structs Man, Woman, Child implement interface Human, then a method with the parameter Human can take any of the structs Man, Woman, Child as an argument. Hence, the

Message Map MFC with multiple inheritance: how to avoid warning C4407 and runtime crashes

故事扮演 提交于 2019-12-01 10:47:31
I recently ported a project from VS2008 to VS2013 and ran into some stack corrupt issues. After some research I could pinpoint the cause to the following code: class CInternalInterface { afx_msg void OnMouseMove(UINT, CPoint) = 0; }; class CMyDlg : public CDialog, public CInternalInterface { afx_msg void OnMouseMove(UINT, CPoint); } BEGIN_MESSAGE_MAP(CMyDlg, CDialog) ON_WM_MOUSEMOVE() END_MESSAGE_MAP() The compiler issued a "warning C4407: cast between different pointer to member representations, compiler may generate incorrect code" at the ON_WM_MOUSEMOVE() statement and at runtime the stack

Dealing with Nested React Components' State Changes

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 09:04:26
So, I have multiple ReactComponent. Initially, I was thinking that there will be sort of a parent component (let's call this GrandPa) with its own state, and it will pass down some info about its state to another component (call it Parent). Similarly, Parent passes some of his to Child and child to GrandChild. So we have the hierarchy: GrandPa -> Parent -> Child -> GrandChild However, I quickly realized that when I change the state of GrandPa with method this.setState(prevState => (<new state based on prevState>)) , the changes do not cascade down the channel. Another problem I realized is

Message Map MFC with multiple inheritance: how to avoid warning C4407 and runtime crashes

怎甘沉沦 提交于 2019-12-01 08:07:44
问题 I recently ported a project from VS2008 to VS2013 and ran into some stack corrupt issues. After some research I could pinpoint the cause to the following code: class CInternalInterface { afx_msg void OnMouseMove(UINT, CPoint) = 0; }; class CMyDlg : public CDialog, public CInternalInterface { afx_msg void OnMouseMove(UINT, CPoint); } BEGIN_MESSAGE_MAP(CMyDlg, CDialog) ON_WM_MOUSEMOVE() END_MESSAGE_MAP() The compiler issued a "warning C4407: cast between different pointer to member

Why only base class default constructor is called in virtual base multiple inheritance? [duplicate]

风流意气都作罢 提交于 2019-12-01 07:17:49
This question already has an answer here: c++ virtual inheritance 3 answers In multiple inheritance, I have a virtual Base class which is inherited by class A and class B . A and B are base classes of AB . Please see the code below. In constructor of A and B , Base(string) constructor is called. I am expecting to get following output: Base::Base(std::string) A::A() B::B() But I am getting following output: Base::Base() A::A() B::B() Why default constructor of Base is being called? #include<iostream> #include<string> using namespace std; class Base{ public: Base(){ cout<<__PRETTY_FUNCTION__<

Derived class implementing multiple interfaces with a common function signature

只谈情不闲聊 提交于 2019-12-01 06:40:29
问题 I'm getting a compile error when I try to compile my code. The error is this: multi.cc: In function ‘int main()’: multi.cc:35: error: cannot declare variable ‘mdc’ to be of abstract type ‘MostDerivedClass’ multi.cc:27: note: because the following virtual functions are pure within ‘MostDerivedClass’: multi.cc:13: note: virtual int Interface2::common_func() multi.cc:36: error: request for member ‘common_func’ is ambiguous multi.cc:13: error: candidates are: virtual int Interface2::common_func()

How does Python's super() actually work, in the general case?

本秂侑毒 提交于 2019-12-01 06:20:12
问题 There are a lot of great resources on super() , including this great blog post that pops up a lot, as well as many questions on Stack Overflow. However I feel like they all stop short of explaining how it works in the most general case (with arbitrary inheritance graphs), as well as what is going on under the hood. Consider this basic example of diamond inheritance: class A(object): def foo(self): print 'A foo' class B(A): def foo(self): print 'B foo before' super(B, self).foo() print 'B foo