inheritance

Inheriting generic can't up cast

我的未来我决定 提交于 2020-01-23 04:05:26
问题 I have a problem with inheriting a custom generic. The compiler (Visual Studio for Mac), complaints that the inheriting generic can't be implicitly converted to another, inheriting type. A break down of my code is as follows: I have an interface called IAnsweredCommon and another interface that inherits from it called IAnsweredAndroid public interface IAnsweredCommon and public interface IAnsweredAndroid : IAnsweredCommon I have two other classes that use these interfaces. public abstract

type casting when objects are of interface references in Java

一个人想着一个人 提交于 2020-01-23 03:33:05
问题 I am familiar with type casting in inheritance model . Let SuperClass and SubClass be parent and child classes; SuperClass superClass = new SubClass() ; -- Here the object instantiated is a subclass object ; but its reference type is SuperClass ; that is only those methods of SuperClass can be called on the subclass object ; Any methods that are not inherited/overridden in subclass cannot be called (that is any unique methods of subclass ). I observed same behavior as above if SuperClass is

Do derived classes indirectly inherit base's assignment operator?

孤街浪徒 提交于 2020-01-23 02:42:15
问题 I'm trying to understand this behaviour but it seems I don't. Please see this code: #include <iostream> using namespace std; class Base { public: void operator=(const Base& rf) { cout << "base operator=" << endl; this->y = rf.y; } int y; Base() : y(100) { } }; class Derived : public Base { public: int x; Derived() : x(100) { } }; int main() { Derived test; Derived test2; test2.x = 0; test2.y = 0; test.operator=(test2); // operator auto-generated for derived class but... cout << test.x << endl

Extending a class

假装没事ソ 提交于 2020-01-23 02:42:08
问题 EDIT Answered: Although my original question didn't explain my needs in exactly the way the answer provided by Konrad Rudolph addressed them, He (by accident or design) essentially wrote for me what I was trying to write! The class itself does not get extended, but has it's functionality extended by making the class aware of new functions which allow it (the class) to handle a wider array of issues. My grateful thanks for an excellent answer which in turn is also a great tutorial, even if it

Python: Force decorator inheritance?

混江龙づ霸主 提交于 2020-01-22 20:09:10
问题 I'm working with quite a large OOP code-base, and I'd like to inject some tracing/logging. The easiest way to do this would be to introduce a decorator around certain methods on some base classes, but unfortunately decorators aren't inherited. I did try something like the following: def trace(fn): def wrapper(instance, *args, **kwargs): result = fn(instance, *args, **kwargs) # trace logic... return result return wrapper class BaseClass(object): def __init__(self, ...): ... self.__call__ =

Diamond inheritance and pure virtual functions

白昼怎懂夜的黑 提交于 2020-01-22 19:54:11
问题 Imagine a standard diamond inheritance. Class A defines pure virtual function fx, class B defines implementation for fx, classes C and D do nothing with fx. When trying to call fx on instance of class D you'll get 'ambiguous function call' error although there is only one implementation of fx. This can be solved by B and C inheriting from A in virtual manner. Is it a correct solution for the problem? How exactly does virtual inheritance handle merging of virtual function tables? A--->B--->D \

SQLAlchemy introspect column type with inheritance

删除回忆录丶 提交于 2020-01-22 17:30:07
问题 Considering this code (and using SQLAlchemy 0.7.7): class Document(Base): __tablename__ = 'document' __table_args__ = { 'schema': 'app' } id = Column(types.Integer, primary_key=True) nom = Column(types.Unicode(256), nullable=False) date = Column(types.Date()) type_document = Column(types.Enum('arrete', 'photographie', name='TYPES_DOCUMENT_ENUM')) __mapper_args__ = {'polymorphic_on': type_document} class Arrete(Document): __tablename__ = 'arrete' __table_args__ = { 'schema': 'app' } __mapper

How would one decorate an inherited method in the child class?

余生长醉 提交于 2020-01-22 14:12:08
问题 I'm not quite sure how to use a decorator on an inherited method. Normally decorators are put before the definition but for an inherited function the definition is given in the parent and not the child class. I would like to avoid rewriting the definition of the method in the child class and simply specify to put the decorator around the inherited method. To make myself clearer, here is a working example of what I mean: class Person(): def __init__(self, age): self.age = age @classmethod def

How would one decorate an inherited method in the child class?

Deadly 提交于 2020-01-22 14:11:35
问题 I'm not quite sure how to use a decorator on an inherited method. Normally decorators are put before the definition but for an inherited function the definition is given in the parent and not the child class. I would like to avoid rewriting the definition of the method in the child class and simply specify to put the decorator around the inherited method. To make myself clearer, here is a working example of what I mean: class Person(): def __init__(self, age): self.age = age @classmethod def

C++ multiple inheritance and vtables

我们两清 提交于 2020-01-22 12:37:49
问题 So going back to basics, I'm trying to wrap my head around vtables and whatnot. In the following example, if I were to, say, pass a B* to some function, how does that function know to call the methods in the vtable of the C object instead of the methods from the vtable of A ? Are there two, separate VTables that are passed to that object? Are interface pointers really just vtables (since interfaces, IIRC, cannot contain property declarations)? What I'm trying to say is, up until I actually