base-class

how to implement casting to a private base class in C++

只谈情不闲聊 提交于 2019-12-11 07:28:14
问题 How to implement casting to a private base class in C++? I don't want to use hacks such as adding a friend etc. Defining public casting operator does not work. EDIT : For example I have: class A { //base class } class AX : private A { //a child } class AY : private A { //another specialized child } class B { //base class void do (A a) {//do } } class BX : private B { //a child void do (AX a) { B::do( static_cast <A> (a) ); } } class BY : private B { //another specialized child void do (AY a)

Need to mock out some base class behavior in a python test case

孤街浪徒 提交于 2019-12-11 05:17:55
问题 My title is fairly descriptive, but here goes. Suppose I have this setup. class BaseClass(object): def __init__(self): pass def base_function(self, param="Hello World"): print param #multiple inheritance probably irrelevant but my problem deals with it class DerivedClass(BaseClass, AnotherBaseClass): def __init__(self): pass def advanced_function(self): #blah blah blah #code code code self.base_function() Now, I have a situation where I am testing a derived class, but in doing so, I need to

C# List of different classes

喜你入骨 提交于 2019-12-11 05:06:55
问题 I did not find the answer in searching for it. I need a List that contains different classes, each of them inherent from a base class BaseA , but each of them will have properties others will not have, or some that uses the same class will. public class BaseA { public int ID = 0; } public class AA : BaseA { public int AID = 0; } public class AB : BaseA { public int BID = 1; } public class AC : BaseA { public int CID = 0; } Now the question is how do I get a single List that may contain class

Structuring classes with multiple inheritance

亡梦爱人 提交于 2019-12-11 04:24:00
问题 This isn't an actual programming question, I just need advice on how to structure a part of my program. The program is divided into a client and a server part. Both share certain code, including base classes. Here's a representation of the code I'm having trouble with: Shared classes: class BaseEntity { public: virtual void EmitSound(std::string snd) {} virtual bool IsPlayer() {return false;} }; class BasePlayer : public BaseEntity { public: bool IsPlayer() {return true;} } Serverside classes

Pass abstract parameter to method, why not?

六月ゝ 毕业季﹏ 提交于 2019-12-10 18:10:03
问题 I've written an abstract class (with pure virtual functions), and I'd like to have a method accept one such class as a parameter. Given that the class is abstract, I understand that I couldn't pass an abstract class to any method, but why can't I pass a subclass of an abstract class to that method? How do I specify that a parameter should be any of the subclasses of a specified baseclass? This is all in C++. 回答1: You need to specify the parameter as a pointer (or reference), e.g. Abstract *

Blocking the possibility to create classes directly bypassing a factory

限于喜欢 提交于 2019-12-10 14:43:31
问题 In a base class for all the models in our MVC system, I created a factory method BaseCLass::getNew() that returns an instance of the requested child class when called via SomeChildClass::getNew(). Now, I'm looking for a way to force the programmer to use this factory. I.e., idially I'd like that any class created directly, like this: new SomeChildClass will throw an exception upon creation, and only classes created by the factory will be usable. Any ideas how can this be achieved? Our code is

override List<baseClass> with List<derivedClass>

雨燕双飞 提交于 2019-12-10 14:07:52
问题 I have base classes like this: public class Scene { public IList<SceneModel> Models {get; set;} } public class SceneModel { } and derived classes like this: public class WorldScene : Scene { public override IList<WorldModel> Models {get; set;} } public class WorldModel : SceneModel { } So my question is, how do I manage this. As it stands the compiler isn't happy with this (and to be honest it looks a bit weird to me anyway). So is what I'm trying to do impossible? And if so, why? Or is it

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

僤鯓⒐⒋嵵緔 提交于 2019-12-10 04:10:28
问题 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

Raise Base Class Events in Derived Classes C#

雨燕双飞 提交于 2019-12-09 10:28:54
问题 I have a base class DockedToolWindow : Form, and many classes that derive from DockedToolWindow. I have a container class that holds and assigns events to DockedToolWindow objects, however I want to invoke the events from the child class. I actually have a question about how to implement what this MSDN site is telling me to do. This section below is giving me the problem: // The event. Note that by using the generic EventHandler<T> event type // we do not need to declare a separate delegate

Inconsistent accessibility: base class is less accessible than child class

半世苍凉 提交于 2019-12-08 18:01:11
问题 I am reading book "C# 4.0 in a nutshell" by Joseph Albabari and Ben Albabari. From there I find a topic restrictions on access modifiers. Page 91, Topic "Restrictions on Access Modifiers". Quoting from the book. The compiler prevents any inconsistent use of access modifiers. For example, a sub- class itself can be less accessible than a base class, but not more So this says that base class should be equally or more accessible than subclass. So if base class is internal then subclass should be