inheritance

C++ - calling derived function from abstract base pointer

不问归期 提交于 2020-01-03 17:26:08
问题 I have been trying to create a TCP Server model based on inheritance, with varying success. These servers are managed by a singleton whose task it is to shut these servers down and other simple maintenance functions: class TCPServer { public: TCPServer(); ~TCPServer(); void Bind(TCPDaemon *daemon) { if(!daemon->IsRunning()) { throw TCPBindException("Daemon is inactive"); } // if the port is not taken, bind this daemon to it if(this->servers.count(daemon->port())==0) { this->servers[daemon-

Is there any way to achieve multiple inheritance in php?

蓝咒 提交于 2020-01-03 17:16:49
问题 Lets say I have a parent class class parent { } ..... This parent has three sub class class child1 { } class child2 { } class child3 { } and these child classes have further smaller parts like class child1subpar1 { } class child1subpar2 { public function foo() { echo "hi"; } } class child2subpar1 { } class child2subpar2 { } Now, how to sum this whole up like class child1 extends child1subpar1, child1subpar2 { } class child2 extends child2subpar1, childsubpar1 { } class parent extends child1

Initializing a static std::map<int, unique_ptr<int>> in C++

对着背影说爱祢 提交于 2020-01-03 17:06:05
问题 This is a similiar question to this post. The answer that I think has the most promise has to do with templated static initialization. Here is the class from that answer: template <typename T, typename U> class create_map { private: std::map<T, U> m_map; public: create_map(const T& key, const U& val) { m_map[key] = val; } create_map<T, U>& operator()(const T& key, const U& val) { m_map[key] = val; return *this; } operator std::map<T, U>() { return m_map; } }; Usage: std::map mymap = create

How to use validity functions correctly with inherited S4 classes in R

狂风中的少年 提交于 2020-01-03 12:08:25
问题 let's assume you have one S4 class "A", and a subclass "B" which has additional features. Each have their own validity checks in place - B should only check the additional features. Now in the initialization of B, I would like to start out from an object of class A, and then amend it with the additional features. However, this creates problems, and I guess I am somewhere violating R's assumptions in this example. Here's the dummy code: setClass(Class="A", representation= representation(x=

C# and C++ class inheritance intermingling

可紊 提交于 2020-01-03 11:50:28
问题 I have an interesting stack of assemblies I want to put together: Common Assembly (C# or C++-CLI) public class MyBase { public void MethodA() { ... } private void MethodB() { ... } protected virtual MethodC() { ... } } Test Code Assemblies (all C++-CLI) public class MySpecific : public MyBase{ protected: override MethodC(); }; Test Simulator (C#) MySpecific obj = new MySpecific(); obj.MethodC(); While assembly 1 could be C++-CLI to keep things simpler, I'd really like to keep assembly 3 in C#

Interface Base class instantiation via generic method

人盡茶涼 提交于 2020-01-03 11:13:08
问题 I have an interface that for example's sake looks like this: interface IFoo<TEnum> where TEnum : struct, IConvertible, IComparable, IFormattable { TEnum MyEnum { get; set; } } I then have an abstract base class that looks like this: abstract class FooBase<TEnum> : IFoo<TEnum> where TEnum : struct, IConvertible, IFormattable, IComparable { public TEnum MyEnum { get; set; } } I then inherit from the base class like so: class MyFoo : FooBase<MyFoo.MyFooEnum> { public enum MyFooEnum { Foo1, Foo2,

Interface Base class instantiation via generic method

早过忘川 提交于 2020-01-03 11:12:30
问题 I have an interface that for example's sake looks like this: interface IFoo<TEnum> where TEnum : struct, IConvertible, IComparable, IFormattable { TEnum MyEnum { get; set; } } I then have an abstract base class that looks like this: abstract class FooBase<TEnum> : IFoo<TEnum> where TEnum : struct, IConvertible, IFormattable, IComparable { public TEnum MyEnum { get; set; } } I then inherit from the base class like so: class MyFoo : FooBase<MyFoo.MyFooEnum> { public enum MyFooEnum { Foo1, Foo2,

C++ compiler error involving private inheritance

孤街醉人 提交于 2020-01-03 10:56:11
问题 Could someone please explain the following compiler error to me: struct B { }; template <typename T> struct A : private T { }; struct C : public A<B> { C(A<B>); // ERROR HERE }; The error at the indicated line is: test.cpp:2:1: error: 'struct B B::B' is inaccessible test.cpp:12:7: error: within this context What exactly is inaccessible, and why? 回答1: Try A< ::B> or A<struct B> . Inside of C , unqualified references to B will pick up the so-called injected-class-name , it is brought in through

How can I override a parent class function with child one in Perl?

偶尔善良 提交于 2020-01-03 09:22:08
问题 I would like to replace parent function (Somefunc) in child class, so when I call Main procedure it should fail. Is it possible in Perl? Code: package Test; use strict; use warnings; sub Main() { SomeFunc() or die "Somefunc returned 0"; } sub SomeFunc() { return 1; } package Test2; use strict; use warnings; our @ISA = ("Test"); sub SomeFunc() { return 0; } package main; Test2->Main(); 回答1: When you call Test2->Main() , the package name is passed as the first parameter to the called function.

Invalid output with inherit class

谁说胖子不能爱 提交于 2020-01-03 08:55:09
问题 I have 2 classes [DataContract, KnownType(typeof(B))] public class A { [DataMember] public string prop1 { get; set; } [DataMember] public string prop2 { get; set; } [DataMember] public string prop3 { get; set; } } [DataContract] public class B : A { [DataMember] public string prop4 { get; set; } } and the following method: List<B> BList = new List<B>(); BList = new List<B>() { new B() { prop1 = "1", prop2 = "2", prop3 = "3", prop4 = "4" } }; List<A> AList = BList.Cast<A>().ToList();