abstract

An abstract method overrides an abstract method

与世无争的帅哥 提交于 2019-12-04 03:28:22
问题 public abstract class A { public abstract void Process(); } public abstract class B : A { public abstract override void Process(); } public class C : B { public override void Process() { Console.WriteLine("abc"); } } This code throws an Compilation Error: 'B' does not implement inherited abstract member 'A.Process()'. Is there any way to do this? 回答1: Just leave out the method completely in class B. B inherits it anyway from A, and since B itself is abstract, you do not explicitly need to

Abstract functions and variable arguments list

我怕爱的太早我们不能终老 提交于 2019-12-04 03:17:53
问题 I have an abstract class an I like to know if it's possible to define an abstract function with variable arguments list? Give me an example if it's possible. 回答1: Yes, it is possible in principle. An example follows below. You can see the output here. Also read about variable arguments list here and here #include <iostream> #include <cstdarg> using namespace std; class AbstractClass{ public: virtual double average(int num, ... ) = 0; }; class ConcreteClass : public AbstractClass{ public:

C++: any way to prevent any instantiation of an abstract base class?

不羁岁月 提交于 2019-12-03 23:29:53
Aside from having a pure virtual function, is there a way to prevent an instantiation of an abstract base class? I can do this: class BaseFoo { virtual void blah() = 0; }; class Foo : public BaseFoo { virtual void blah() {} }; but I'd like to avoid a vtable. (as per my other question about virtual destructors ) Microsoft ATL has ATL_NO_VTABLE to accomplish this (or at least I think that's what it does...) A really obvious way is to declare a protected constructor, and to declare public constructors in the non-abstract derived classes. This of course shifts the burden of corectness to the

How to force implementation of a method in subclass without using abstract?

余生长醉 提交于 2019-12-03 23:10:39
I want to force subclass to implement an implemented method of my mother class. I look this Java - Force implementation of an implemented method but i can't convert my mother class to an abstract class. public class myMotherClass { myMethod { ...some code .. } } public class myClass extends myMotherClass { myMethod { ... other code ... } } So, in this exemple, I want to force myClass implement myMethod. Sorry for my english... You can not force a subclass to override a method. You can only force it to implement a method by making it abstract. So if you can not make myMotherClass abstract you

Convincing Swift that a function will never return, due to a thrown Exception

纵然是瞬间 提交于 2019-12-03 16:32:12
问题 Because Swift does not have abstract methods, I am creating a method whose default implementation unconditionally raises an error. This forces any subclass to override the abstract method. My code looks like this: class SuperClass { func shouldBeOverridden() -> ReturnType { let exception = NSException( name: "Not implemented!", reason: "A concrete subclass did not provide its own implementation of shouldBeOverridden()", userInfo: nil ) exception.raise() } } The problem: Because the function

How can I implement abstract static methods in Java?

梦想的初衷 提交于 2019-12-03 16:21:17
问题 There are numerous questions about the impossibility of including static abstract Java methods. There are also quite a lot about workarounds for this (design flaw/design strength). But I can't find any for the specific problem I'm going to state shortly. It seems to me that the people who made Java, and quite a lot of the people who use it, don't think of static methods the way I, and many others, do - as class functions, or methods that belong to the class and not to any object. So is there

No enclosing instance of type PerfHelper is available due to some intermediate constructor invocation

半城伤御伤魂 提交于 2019-12-03 16:12:59
问题 Consider the below code: class abstract Normal1 extends Something { } class Outer { class abstract Inner extends Normal1 { } } class General extends Outer.Inner // Problem occurs at this { } The error I am getting is "No enclosing instance of type PerfHelper is available due to some intermediate constructor invocation" My question is can I extend the inner class like above ? 回答1: Declare the inner class as static and you should be able to extend it: class outer { static abstract class inner

How to get the name of the calling class (in PHP)

被刻印的时光 ゝ 提交于 2019-12-03 15:04:53
问题 define('anActionType', 1); $actionTypes = array(anActionType => 'anActionType'); class core { public $callbacks = array(); public $plugins = array(); public function __construct() { $this->plugins[] = new admin(); $this->plugins[] = new client(); } } abstract class plugin { public function registerCallback($callbackMethod, $onAction) { if (!isset($this->callbacks[$onAction])) $this->callbacks[$onAction] = array(); global $actionTypes; echo "Calling $callbackMethod in $callbacksClass because

Call function in function from another class PHP

蓝咒 提交于 2019-12-03 14:55:18
问题 I have read a few threads about abstract class here at Stackoverflow and I think it's what I need, but I can't get the declaration straight. What I want to do is to call a function2 (in classB) in a function1 (in classA). How should I do this? 回答1: If you only need to access ClassB's method from ClassA but don't need a parent-child relationship between the two, a static method may be more appropriate: class ClassA { public function method1() { echo ClassB::method2(); } } class ClassB { public

Get the parameter prefix in ADO.NET

老子叫甜甜 提交于 2019-12-03 14:13:17
I want to generate several SQL statements based on a column list using the column names as parameters. Edit : C# var columns = new string[] { "COL1", "COL2" }; var tableName = "TABLE_1"; var prefix = "@"; // TODO get this from the provider factory string sqlInsert = string.Format( "INSERT INTO {0}\n( {1}) VALUES\n({2})", tableName, string.Join(", ", columns), string.Join(", ", columns.Select(c => prefix + c))); Generated SQL: INSERT INTO TABLE_1 ( COL1, COL2) VALUES (@COL1, @COL2) This works with the SqlClient. But I'm using the abstract classes in System.Data ( DbCommand , DbParameter , etc.)