overriding

How to hide a protected procedure of an object?

痞子三分冷 提交于 2019-12-22 05:12:08
问题 In one base class, there's a protected procedure. When inheriting that class, I want to hide that procedure from being used from the outside. I tried overriding it from within the private and even strict private sections, but it can still be called from the outside. The Original class is not mine, so I can't change how TOriginal is defined. Is it possible to hide this procedure in my inherited class? And how? type TOriginal = class(TObject) protected procedure SomeProc; end; TNew = class

What does that have to do with function overloading?

只愿长相守 提交于 2019-12-22 05:04:08
问题 This is basically a copy from the example given in Item 21. Overriding Virtual Functions in Herb Sutter's book Exceptional C++ . #include <iostream> #include <complex> using namespace std; class Base { public: virtual void f(int); virtual void f(double); virtual ~Base() {}; }; void Base::f(int) { cout << "Base::f(int)" << endl; } void Base::f( double ) { cout << "Base::f(double)" << endl; } class Derived: public Base { public: void f(complex<double>); }; void Derived::f(complex<double>) {

Can I over-ride Ruby methods written in C?

☆樱花仙子☆ 提交于 2019-12-22 04:29:18
问题 Is it possible to over-ride methods that are part of Ruby itself, such as rb_error_frozen , that are written in C, with Ruby code? Background : I'm wondering if it's possible to make Ruby merely log a warning, rather than raise an exception, when a frozen object is modified. That way, I can log a variety of state modifications, rather than stopping when the first one occurs. I'm primarily thinking of doing this with YARV, but I could use another implementation if that made it easier. And yes,

Is it possible to override a function in C++ child class without using virtual keyword to the function in parent class which is abstract?

扶醉桌前 提交于 2019-12-22 04:01:18
问题 class Parent { public: void func1(); // Complete meaningful definition in parent given. virtual HRESULT func2()=0; // Bcoz of this function Parent class is abstract. }; class Child: public Parent { public: void func1(); // Different definition in child. }; Is this possible in C++ ? I am overriding func1() which is NOT virtual and it already has a definition in parent abstract class. 回答1: [assuming here Child extends Parent , unlike what the code snap shows] Yes it is possible [it is called

Changing the params modifier in a method override

╄→гoц情女王★ 提交于 2019-12-22 03:57:04
问题 I'm aware that a params modifier (which turns in one parameter of array type into a so-called "parameter array") is specifically not a part of the method signature. Now consider this example: class Giraffid { public virtual void Eat(int[] leaves) { Console.WriteLine("G"); } } class Okapi : Giraffid { public override void Eat(params int[] leaves) { Console.WriteLine("O"); } } This compiles with no warnings. Then saying: var okapi = new Okapi(); okapi.Eat(2, 4, 6); // will not compile! gives an

TypeScript override ToString() [closed]

大憨熊 提交于 2019-12-22 01:46:56
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 months ago . Let's say I have a class Person which looks like this: class Person { constructor( public firstName: string, public lastName: string, public age: number ) {} } Is it possible to override the toString() method in this class, so I could do something like the following? function alertMessage(message: string) {

Odoo: How to override original function

雨燕双飞 提交于 2019-12-21 21:27:38
问题 In Odoo, the quantities of a product are calculated each time the products form is opened. This happens in model product.product ==> function _product_available. This function returns a dictionary called res. Example: res = {8: {'qty_available': 5000.0, 'outgoing_qty': 1778.5, 'virtual_available': 3221.5, 'incoming_qty': 0.0}} Now I want to modify those values. I've managed to do this by coding it directly in the original function _product_available. Since this is not the correct way to do

C# & generics - why is method in base class called instead of new method in derived class?

China☆狼群 提交于 2019-12-21 12:58:39
问题 If the generic type argument (of either a calling class or calling method) is constrained with where T : Base the new method in T == Derived is not called, instead the method in Base is called. Why is the type T ignored for method call even though it should be known before run time? Update : BUT, when the constraint is using an interface like where T : IBase the method in Base class is called (not the method in interface, which is also impossible). So that means the system actually is able to

Overriding Javascript Confirm() while preserving the callback

半城伤御伤魂 提交于 2019-12-21 12:51:51
问题 To the point, I want to override the standard js confirm() function within a jQuery plugin. I have figured out how to do it with the simple function layout below. function confirm(opts) { //code } Now, what I want to do is call another function within the confirm function above, like so... function confirm(opts) { openModal(opts); } The openModal function will open a custom modal window with the message and required buttons. The buttons are both <span> with the id of either submit or cancel .

Django Models: Override a field return value

不想你离开。 提交于 2019-12-21 12:50:51
问题 I'm wondering if it is possible to override the default value of a field when it is returned. Say I had a model: class ModelA(models.Model) name = models.CharField(max_length=30) Is there any way that calling modela_instance.name can return a modified value, for example name + " foo", but have the code that appends foo run by default within the model itself, so all I would need to do is call name to get the appended value? I should elaborate and say that what I'm actually hoping to do is have