inheritance

C++ inheritance and name hiding [duplicate]

我是研究僧i 提交于 2020-01-24 09:28:23
问题 This question already has answers here : Why does an overridden function in the derived class hide other overloads of the base class? (4 answers) Closed 2 years ago . I know this is not the first question on this subject, but all the other related questions (and answers) I read were slightly out of the point, according to me. Take the code #include <iostream> using namespace std ; class Base { public: void methodA() { cout << "Base.methodA()" << endl ;} }; class Derived : public Base { public

Diamond inheritance with mixed inheritance modifers (protected / private / public)

守給你的承諾、 提交于 2020-01-24 05:43:07
问题 let's say we have class A,B,C,D where A is base, B,C are between and D is derived in diamond model. NOTE: class B inherits virtualy class A in private mode, class C inherita virtualy class A in protected mode. class A { public: int member; // note this member }; class B : virtual private A // note private { }; class C : virtual protected A // note protected { }; class D : public B, // doesn't metter public or whatever here public C { }; int main() { D test; test.member = 0; // WHAT IS member?

Is it possible to be a virtual subclass of a built in type?

自闭症网瘾萝莉.ら 提交于 2020-01-24 05:42:26
问题 Is it possible to make a user defined type be a virtual subclass of a built in type in python? I would like my class to be considered a subclass of int , however I don't want to inherit directly like this: class MyInt(int): '''Do some stuff kind of like an int, but not exactly''' pass Since then my class becomes effectively immutable, whether I want it to be or not. For instance, it becomes impossible to use methods like __iadd__ and __isub__ since int has no way to modify itself. I could

how to tell if two javascript instances are of the same class type?

爱⌒轻易说出口 提交于 2020-01-24 05:14:41
问题 I'm using John Resig's Simple Inheritance Class to define some classes, say: var MyClass = Class.extend({}); var MyOtherClass = Class.extend({}); then I have some instances var instanceA = new MyClass(); var instanceB = new MyClass(); var instancec = new MyOtherClass(); How can I determine if instanceA is of the same "type" as instanceB ? Note: I'm not asking to check if they are both a MyClass , I need to determine the class of one, and then see if the other is the same, regardless of

Hierarchy violates Liskov - so what?

给你一囗甜甜゛ 提交于 2020-01-24 03:16:05
问题 I am using an API that violates the Liskov substitution principle : it throws its own Exception type that extends Exception, but puts the exception message from the base class in a new ErrorCode field and puts its own (useless) message in the Message field. Therefore to display the correct message I need to cast the Exception to the DerivedException type and use the ErrorCode field. If I treat it as an Exception object I get the wrong message. Now this irks me on a stylistic level, but it is

How can I rebless an object in Perl 6?

吃可爱长大的小学妹 提交于 2020-01-24 03:11:05
问题 Another question might be "How do I inherit from builtin types?". I have two questions really, but they are both from the same thing I'm playing with. First, I can make a subset of a type when I want to constrain it further. I do that with MyInt which accepts anything that is an Int . I declare a variable to by MyInt and assign to it, but when I check its name, I get Int instead. So, what's up with that? subset MyInt where * ~~ Int; my MyInt $b = 137; put 'Name: ', $b.^name; # Int, but why

Custom XML-element name for base class field in serialization

允我心安 提交于 2020-01-24 00:30:09
问题 How can I change XML-element name for field inherited from base class while doing serialization? For example I have next base class: public class One { public int OneField; } Serialization code: static void Main() { One test = new One { OneField = 1 }; var serializer = new XmlSerializer(typeof (One)); TextWriter writer = new StreamWriter("Output.xml"); serializer.Serialize(writer, test); writer.Close(); } I get what I need: <?xml version="1.0" encoding="utf-8"?> <One xmlns:xsi="http://www.w3

Javascript Distinguish between Composition vs. Inheritance

[亡魂溺海] 提交于 2020-01-23 19:25:15
问题 in the classfull-Style (c++) or in the traditional Design Patterns (GofPatterns) it is really clear, what is the difference between composition and inheritance and how it is implemented and when to use what (advantages/disadvantages). But how do you distingish between Composition or the "normal" Inheritance in JS? or it is used as the same term? Is a prototype inheritance for example defined as a composition or inheritance? What are you guys thinking? 回答1: Is a prototype inheritance for

dynamic_cast doubt from C++/Stroustrup : converting to protected base class

百般思念 提交于 2020-01-23 10:11:05
问题 I know that following code gives compilation error : class A{ public : virtual void name(){cout<<typeid(this).name()<<endl;}; }; class B:protected A{public : virtual void name(){cout<<typeid(this).name()<<endl;};}; void foo(B* b) { A * a = dynamic_cast<A*>(b); //Error : 'A' is an inaccessible base of 'B' return; } But then why in the C++ Stroustrup book (15.4.1) he writes class BB_ival_slider:public Ival_slider,protected BBslider{ //... }; void f(BB_ival_slider*p) { // ok BBslider* pbb2 =

Inheritance in Lua

筅森魡賤 提交于 2020-01-23 10:01:30
问题 I am trying to make a simple api that eases the process of creating classes and sub-classes. function newClass(index,...) local new_class = {} setmetatable(new_class,{__index = index}) local optionalArgs = {...} if optionalArgs[1] ~= nil then setmetatable(new_class,optionalArgs[1]) end return new_class end --TESTINGCODE exampleSuper = newClass({name="Super",id=1,getName = function() print("Super") end,}) exampleSuper.getName() exampleSub = newClass({name="Sub",},exampleSuper) print(exampleSub