inheritance

Accessing an implemented abstract property in the constructor causes CA2214: Do not call overridable methods in constructors

*爱你&永不变心* 提交于 2020-01-13 08:17:24
问题 public abstract class MyBase { public abstract bool MyProperty { get; protected set; } } public class MyClass : MyBase { public MyClass() { this.MyProperty = true; } public override bool MyProperty { get; protected set; } } The constructor MyClass() causes CA2214: Do not call overridable methods in constructors. This normally only shows if one calls a virtual method defined in the same class as the constructor. e.g. Accessing MyProperty inside MyBase 's constructor. Here I am calling a non

Use of 'using' keyword to make inherited constructor public [duplicate]

夙愿已清 提交于 2020-01-13 08:17:20
问题 This question already has an answer here : C++11 inheriting constructors and access modifiers (1 answer) Closed 5 years ago . I am trying to test protected methods and constructors of my class. For this purpose, I tried to subclass it, and re-export its members as public with C++11 using keyword: class Foo { protected: Foo(int i) {} void run() {} }; class TestableFoo : public Foo { public: using Foo::Foo; using Foo::run; }; int main() { TestableFoo foo(7); foo.run(); } However, both g++ and

Use of 'using' keyword to make inherited constructor public [duplicate]

匆匆过客 提交于 2020-01-13 08:14:09
问题 This question already has an answer here : C++11 inheriting constructors and access modifiers (1 answer) Closed 5 years ago . I am trying to test protected methods and constructors of my class. For this purpose, I tried to subclass it, and re-export its members as public with C++11 using keyword: class Foo { protected: Foo(int i) {} void run() {} }; class TestableFoo : public Foo { public: using Foo::Foo; using Foo::run; }; int main() { TestableFoo foo(7); foo.run(); } However, both g++ and

Use interface inheritance or just implement all the interfaces directly?

时光总嘲笑我的痴心妄想 提交于 2020-01-13 06:37:08
问题 I don't necessarily see a grandiose benefit of interfaces inheriting interfaces. Consider the following three interfaces, the third inheriting the other two interface IOne { } interface ITwo { } // interface inheritance interface IAll : IOne, ITwo { } Is it best to class C : IOne, ITwo { ... } or class C : IAll { ... } If the latter can be beneficial then why not just create IAll to have all the methods of both IOne and ITwo without inheriting from them? After all it's an interface. Is

Dynamic Pointer Cast

家住魔仙堡 提交于 2020-01-13 06:07:27
问题 I'd like to convert a base class pointer to a derived class pointer as a function argument without using dynamic_pointer_cast class Base { public: typedef std::shared_ptr < Base > Ptr; virtual ~Base ( ); ... }; class Derive : public Base { public: typedef std::shared_ptr < Derive > Ptr; ... }; void foo( Derive::Ptr ptr ) { ... } Base::Ptr ptr1 ( new Derive ); foo( ptr1 ); The above code will give an error while calling foo. This can be avoided by typecasting ptr1 into a Dervie pointer using

Are the private members of superClass inherited by a subClass… Java?

拈花ヽ惹草 提交于 2020-01-13 05:42:31
问题 I have gone through this: Do subclasses inherit private fields? But I'm still confused... I'm talking about inheriting only and not accessing. I know that they aren't visible out side class. But does the subclass' object has it's own copies of those private members in super class? For example... class Base { private int i; } class Derived extends Base { int j; } Now, Base b = new Base(); Derived d = new Derived(); size of int is 4 Now, Will the size of b be 4 and size of d be 8 or size of d

Java Variables Shadowed Methods overridden concept

匆匆过客 提交于 2020-01-13 05:20:21
问题 I am struggling to understand Variables Shadowed Methods Overriden Concept of inheritance with Java. Case 1: class Car{ public int gearRatio = 8; public String accelerate() { return "Accelerate : Car"; } } class SportsCar extends Car{ public int gearRatio = 9; public String accelerate() { return "Accelerate : SportsCar"; } public static void main(String[] args){ Car c = new SportsCar(); System.out.println( c.gearRatio+" "+c.accelerate() ); } } Output: 8 Accelerate : Sportscar. Case 2: public

Extending HMVC modules in CodeIgniter

萝らか妹 提交于 2020-01-13 05:07:50
问题 Let's say we have module called core_crud with something like this in the controller: if (!defined('BASEPATH')) exit('No direct script access allowed'); class Core_crud extends MX_Controller { function __construct() { parent::__construct(); $this->load->model('mdl_core_crud'); } public function index() { // code goes here } } And now I want to extend this module with another module called shop_crud . How would the basic controller for this shop_crud module look like? I mean I want to inherit

Generic visitor base class template in C++ - overload issue

﹥>﹥吖頭↗ 提交于 2020-01-13 03:55:40
问题 I thought it would be a simple exercise to write a generic visitor base class template. The goal is to be able to write typedef visitor<some_base, some_derived1, some_derived2> my_visitor; ...and then have my_visitor be a type that is functionally equivalent to struct my_visitor { virtual void visit(some_base&) {} virtual void visit(some_derived1&) {} virtual void visit(some_derived2&) {} }; which i can inherit with actually useful derived visitor classes for that type hierarchy, which

Entity Framework Table Per Type Performance

早过忘川 提交于 2020-01-12 19:05:51
问题 So it turns out that I am the last person to discover the fundamental floor that exists in Microsoft's Entity Framework when implementing TPT (Table Per Type) inheritance. Having built a prototype with 3 sub classes, the base table/class consisting of 20+ columns and the child tables consisting of ~10 columns, everything worked beautifully and I continued to work on the rest of the application having proved the concept. Now the time has come to add the other 20 sub types and OMG, I've just