base-class

C++: Protected Class Constructor

余生长醉 提交于 2019-12-08 16:23:34
问题 If a class is always going to be inherited, does it make sense to make the constructor protected ? class Base { protected: Base(); }; class Child : protected Base { public: Child() : Base(); }; Thanks. 回答1: That only makes sense if you don't want clients to create instances of Base , rather you intend it to be base-class of some [derived] classes, and/or intend it to be used by friends of Base (see example below). Remember protected functions (and constructors) can only be invoked from

C# - Hiding all methods of the UserControl class from a derived one

陌路散爱 提交于 2019-12-08 05:19:04
问题 I have a custom user control. Normally it inherites the UserControl class. But by this way it inherites all the public methods and properties of UserControl . But I want to hide all these and implement my own few methods and properties. Say that I have a custom control named CustomControl . public class CustomControl : UserControl When I create an instance of CustomControl : CustomControl cControl = new CustomControl(); When I type cControl. intellisense offers me all the methods and

MVC3 passing base class to partial View - submitting form only has parent class values

耗尽温柔 提交于 2019-12-07 16:03:41
问题 I have a number of child ViewModel classes which inherit from an base ViewModel class. I pass my child ViewModel into my View, which then passes itself into a partial view. The main view takes the child type, but the partial view takes the Parent type. Everything displays correctly when I manually populate the properties. However, when I Submit the form, my controller action only has properties for the Child class - none of the base class properties are completed? e.g. public abstract class

Generic Entity Base Class

独自空忆成欢 提交于 2019-12-06 09:23:49
问题 I've just read a post about Generic Entity Base Classes. Simply and if I'm not wrong, the main idea in behind is collecting all generic, non-entity-spesific fields in one interface, than implement it in main entities. It's going to be a TL:DR; Let's see some code. This is the base entity interface and it's generic impementation to another interface public interface IEntity : IModifiableEntity { object Id { get; set; } DateTime CreatedDate { get; set; } DateTime? ModifiedDate { get; set; }

Access “this” pointer of concrete class from interface

筅森魡賤 提交于 2019-12-06 06:02:56
After writing a test, I determined that the this pointer in an interface is not equal to the this pointer of the concrete class, meaning I can't just use a C-style cast on it. class AbstractBase {...}; class AnInterface { public: AnInterface() {...} // need AbstractBase * here ~virtual AnInterface() {...} // and here }; class Concrete : public AbstractBase, public AnInterface {}; My interface needs a base class pointer to the concrete class inheriting it in the constructor and destructor in order to handle interface related registration and deregistration. Every concrete object that inherits

Several activities using same listener

本小妞迷上赌 提交于 2019-12-06 05:46:33
I got 4 activites that all include a xml-footer which contains 4 buttons (one for each activity). I would now like to setup onclicklisteners to these buttons (it's a self made menu in the footer). The question is, how do I use listeners so that I can reuse code? I have two ideas: Create a class that implements onclicklistener and in every activity i would get the buttons and then create a new instance of the listener class and do button.setOnClickListener(onClickListener) The problem is that in the listener class, how would i check which button called the event? And how would I create an

ASP.NET CodeFileBaseClass attribute vs. inherit from System.Web.UI.Page

╄→гoц情女王★ 提交于 2019-12-06 04:21:37
问题 I've just created a base class for my pages by inheriting from System.Web.UI.Page : public abstract class PageBase : System.Web.UI.Page { ... } When I noticed that you can also declare a base page in an ASP.NET view: <%@ Page Language="C#" CodeFileBaseClass="PageBase.cs" CodeFile="page.aspx.cs" Inherits="page" %> Can someone explain what the pros and cons of either method are? When would you use one over the other, or are they both the same? What happens if you used both at the same time? 回答1

MVC3 passing base class to partial View - submitting form only has parent class values

丶灬走出姿态 提交于 2019-12-06 00:08:28
I have a number of child ViewModel classes which inherit from an base ViewModel class. I pass my child ViewModel into my View, which then passes itself into a partial view. The main view takes the child type, but the partial view takes the Parent type. Everything displays correctly when I manually populate the properties. However, when I Submit the form, my controller action only has properties for the Child class - none of the base class properties are completed? e.g. public abstract class BaseDetails { public string Name { get; set; } public BaseDetails() { } public BaseDetails(string name)

Casting List of derived class to List of base class still returning objects of derived class

落花浮王杯 提交于 2019-12-05 17:44:40
I have the following code: public class BaseClass { public string A { get; set; } } public class DerivedClass : BaseClass { public string B { get; set; } } List<DerivedClass> _derivedClass = new List<DerivedClass>() { new DerivedClass() { A = "test1", B = "test2" } }; List<BaseClass> _baseClass = _derivedClass.Cast<BaseClass>.ToList(); The code compiles without any error, however, I expected _baseClass to only contain Property A (object of type BaseClass ), but it's return both A and B properties (objects of type DerivedClass ). What am I missing and what's the correct way to convert a List of

Can a derived class be made uncopyable by declaring copy constructor/operator private in base class?

橙三吉。 提交于 2019-12-05 04:48:04
I thought in theory the answer to this question was yes. However, in practice, my compiler (VS2010) does not seem to complain in the following situation: I have an abstract base class providing some common interface (yet having no data members) and various sub and subsubclasses derived from it. class Base { public: Base() {} virtual ~Base() {} virtual void interfaceFunction1() = 0; virtual void interfaceFunction2() = 0; private: Base(const Base&); // all derived classes should be uncopyable Base& operator=(const Base&); // no data members }; My compiler found it unproblematic to even implement