multiple-inheritance

Type not inherited in SFINAE for multiple inheritance?

吃可爱长大的小学妹 提交于 2019-12-10 19:48:12
问题 I am using a SFINAE mechanism to deduce a type. Resolve<T>::type is deduced to T if class T doesn't contain yes and it's deduced to MyClass if it contains yes . class MyClass {}; template<typename> struct void_ { typedef void check; }; template<typename T, typename = void> struct Resolve { typedef T type; }; template<typename T> struct Resolve <T, typename void_<typename T::yes>::check> { typedef MyClass type; }; Now, I have the simple test classes as, struct B1 { typedef int yes; }; // 1

Multiple inheritance and the this pointer

筅森魡賤 提交于 2019-12-10 18:33:40
问题 Suppose I have this struct: struct vector_data { double x, y; double& operator[](size_t index) { return * (static_cast<double*>(static_cast<void*>(this)) + index); } }; The operator[] should work as expected, because vector_data is a POD type. The expected behaviour is that vector_data[0] returns x, and vector_data[1] returns y. Now suppose I have a second struct: struct more_data { double evil_data; // There could be more here, data or functions }; And derive from both like this: struct

Overloading member function among multiple base classes

扶醉桌前 提交于 2019-12-10 18:02:07
问题 Basically I want to have multiple member functions with same name, but different signature, spread in multiple base classes. Example: #include <iostream> struct A { void print(int) { std::cout << "Got an int!" << std::endl; } }; struct B { void print(double) { std::cout << "Got a double!" << std::endl; } }; struct C : A, B {}; int main() { C c; c.print((int)0); return 0; }; But I got this error on clang: main.cpp:18:7: error: member 'print' found in multiple base classes of different types c

How does C++ pick which overloaded function to call?

天大地大妈咪最大 提交于 2019-12-10 17:16:27
问题 Say I have three classes: class X{}; class Y{}; class Both : public X, public Y {}; I mean to say I have two classes, and then a third class which extends both (multiple-inheritance). Now say I have a function defined in another class: void doIt(X *arg) { } void doIt(Y *arg) { } and I call this function with an instance of both: doIt(new Both()); This causes a compile-time error, stating that the function call is ambiguous. What are the cases, besides this one, where the C++ compiler decides

Multiple Inheritance with abstract and defined inherited functions of the same name

前提是你 提交于 2019-12-10 17:01:01
问题 First off I apologize if there is another post out there that answers this, all the similar posts I found dealt with diamond inheritance schemes or defined functions, which this does not. In short, I'm wondering if it is possible to have one class inherit from two other classes where both child classes has a function with the same name and arguments but it is defined in one child class, and pure-virtual in another. Furthermore if I can do this, would invoking the function on the pure-virtual

Requiring an argument extends a particular class AND implements a particular interface

╄→гoц情女王★ 提交于 2019-12-10 15:56:52
问题 I have two Java class hierarchies that share a common ancestor and implement a common interface. I need to pass a pointer to one of these things to a method in another class. interface I { ... } class A extends java.awt.Component implements I { ... } class B extends java.awt.Component implements I { ... } class D { Component c; I i; void m(? x) { c = (Component) x; i = (I) x; } } Is there something I can replace the ' ? ' with that will allow me pass in either an ' A ' or a ' B '? If I cast '

Multiple inheritance, virtual methods collision and pointers from base classes

做~自己de王妃 提交于 2019-12-10 15:07:47
问题 I have a result that I didn't expect from multiple inheritance, virtual methods and pointers to base classes. With d.getStr() , when d is a derived instance, the base_2 version is called, as I expected. With p->getStr() , when p is a pointer to a derived instance (or a pointer to base_2 pointing to a derived instance), the base_2 version is called, as I expected. But with p->getStr() , when p is a pointer to a base_1 pointing to a derived instance, the base_1 version is called and I was

Simulating Multiple Table Inheritance in Linq-to-SQL

你离开我真会死。 提交于 2019-12-10 15:05:57
问题 By now, everyone knows that Linq-to-SQL does not natively support multiple table inheritance (a.k.a., table-per-subtype) and that you can use other ORM frameworks such as the Entity Framework, NHibernate, etc. instead if you want native support for multiple table inheritance (reference the SO question "Multiple Inheritance in LINQtoSQL" if you have any doubts). However, supposing that you did want to use (or were limited to use) Linq-to-SQL as your ORM layer, has anyone identified a simple

Ambiguous class inheritance

一世执手 提交于 2019-12-10 14:09:20
问题 #include <iostream> #include <cmath> using namespace std; class Tcirculo{ float radio; float diametro; float area; public: void carea(float r){radio= r; area=(M_PI*((r*r)));} float cdiam(float r) {diametro = 2*r; return diametro;} float getr(){return radio;} float getd(){return diametro;} float geta(){return area;} }; class Trectangulo : public Tcirculo{ float altura; public: float calca(float h, float r){altura =h; float arearec = getd() * h; return arearec;} }; class Tcilindro : public

multiple python class inheritance

非 Y 不嫁゛ 提交于 2019-12-10 11:39:44
问题 I am trying to understand python's class inheritance methods and I have some troubles figuring out how to do the following: How can I inherit a method from a class conditional on the child's input? I have tried the following code below without much success. class A(object): def __init__(self, path): self.path = path def something(self): print("Function %s" % self.path) class B(object): def __init__(self, path): self.path = path self.c = 'something' def something(self): print('%s function with