inheritance

Abstract enum in c#

南笙酒味 提交于 2020-01-01 15:07:40
问题 Is there a way to make a ( protected ) enum abstract in C#? Example of base class: protected abstract enum commands{}; //CS0106 protected abstract void useCommands(commands meh); This does not compile, since " abstract is not valid for this item". Is there a working way to achive the desired behaviour? 回答1: All enums must derive from System.Enum All enums are value types and hence sealed. Because of above these two rules, you cannot inherit enums. 回答2: enum is a keyword , not a class name : /

C++: Passing reference of constructing object to constructed member objects?

空扰寡人 提交于 2020-01-01 12:11:24
问题 Okay, consider the following classes: class Object { public: // Constructor Object() : [Initialization List] { ... } ... }; class Container { public: Object A; Object B; .... Container() : [Initialization List] { } }; I'd like to provide [access to Container and it's members] to the Objects. My first thought was to somehow pass a reference to the current Container object to the constructors of the Objects. But I can't figure out how to do this. I've messed around with "this", but I'm not

C++ Inheritance, calling a derived function from the base class

。_饼干妹妹 提交于 2020-01-01 12:01:32
问题 How can I call a derived function from a base class? I mean, being able to replace one function from the base to the derived class. Ex. class a { public: void f1(); void f2(); }; void a::f1() { this->f2(); } /* here goes the a::f2() definition, etc */ class b : public a { public: void f2(); }; /* here goes the b::f2() definition, etc */ void lala(int s) { a *o; // I want this to be class 'a' in this specific example switch(s) { case 0: // type b o = new b(); break; case 1: // type c o = new c

Can T in template <typename T> use inheritance?

非 Y 不嫁゛ 提交于 2020-01-01 11:51:10
问题 I want to do something like this: template <typename T:public Vertex> addTri( T v1, T v2, T v3 ) { // Take v1.pos, v2.pos, v3.pos and create a geometric repn.. Triangle tri( v1.pos, v2.pos, v3.pos ) ; // all vertices will // have to have a .pos member. // Create the vertex buffer.. VertexBuffer<T> vb ... } Since that doesn't work, this is my workaround.. template <typename T> addTri( T v1, T v2, T v3 ) { Vertex* p1 = (Vertex*)&v1 ; // This is a very "shut up C++, I know what I'm doing" type

Copying Methods from Member

一世执手 提交于 2020-01-01 11:05:10
问题 I have a simple, low-level container class that is used by a more high-level file class. Basically, the file class uses the container to store modifications locally before saving a final version to an actual file. Some of the methods, therefore, carry directly over from the container class to the file class. (For example, Resize() .) I've just been defining the methods in the file class to call their container class variants. For example: void FileClass::Foo() { ContainerMember.Foo(); } This

in kotlin, how to pass back a MutableList where the destination expects a List

狂风中的少年 提交于 2020-01-01 10:58:29
问题 having a hashMap with List as value defined: private var mMap: HashMap<String, List<DataStatus>>? = null having a function return a hashMap but with the value of MutableList fun getDataStatus(response: JSONObject?): HashMap<String, MutableList<DataStatus>> { return HashMap<String, MutableList<AccountStatusAlert>>() } when pass the result to the hashMap expecting List it got error: mMap = getDataStatus(resp) //<== got error got error: Error:(81, 35) Type mismatch: inferred type is HashMap

Inheriting Nested classes into Subclass

谁说我不能喝 提交于 2020-01-01 10:17:06
问题 When I was going through this article, under the section Private Members in a Superclass , i saw this line A nested class has access to all the private members of its enclosing class—both fields and methods. Therefore, a public or protected nested class inherited by a subclass has indirect access to all of the private members of the superclass. My question is how can we DIRECTLY access the Nested class of Base in Derived (like we can access any public , protected fields)? and if there is a

Inheriting Nested classes into Subclass

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 10:15:34
问题 When I was going through this article, under the section Private Members in a Superclass , i saw this line A nested class has access to all the private members of its enclosing class—both fields and methods. Therefore, a public or protected nested class inherited by a subclass has indirect access to all of the private members of the superclass. My question is how can we DIRECTLY access the Nested class of Base in Derived (like we can access any public , protected fields)? and if there is a

Override/Rewrite a javascript library function

主宰稳场 提交于 2020-01-01 09:58:12
问题 I am using an open source javascript library timeline.verite.co It's a timeline library which works great on page load. But when I try to repaint the timeline on certain condition, it starts giving out weird errors I would like to modify the init function in the library. But instead of changing it in the original library itself, I would like to rewrite/override this function in another separate .js file so that when this function is called, instead of going to the original function, it must

Pickle a dict subclass without __reduce__ method does not load member attributes

时光总嘲笑我的痴心妄想 提交于 2020-01-01 09:22:46
问题 I have the need to ensure that a dict can only accept a certain type of objects as values. It also have to be pickable. Here is my first attempt: import pickle class TypedDict(dict): _dict_type = None def __init__(self, dict_type, *args, **kwargs): super().__init__(*args, **kwargs) self._dict_type = dict_type def __setitem__(self, key, value): if not isinstance(value, self._dict_type): raise TypeError('Wrong type') super().__setitem__(key, value) If I test it with the following code (python 3