overriding

C++ overridden function not called

余生颓废 提交于 2019-12-04 06:24:32
问题 I am running into an issue where an overloaded function is not called, and the base function is called instead. I suspect this is related to how things are split between the project files. In files obj1.h/obj1.cpp I have something like this class obj1{ public: void print(); }; void obj1::print(){ cout << "obj1::print()"; } In files obj2.h/obj2.cpp I have something like this: #include "obj1.h" class obj2 : public obj1{ public: void print(); }; void obj2::print(){ cout << "obj2::print()"; } In

Override public method in subclass in a way that restricts public access while still allowing access from parent class?

蓝咒 提交于 2019-12-04 06:19:36
问题 I have a generic Collection class, with a variety of public getter methods. To get one item from the Collection, you call get(). There are also several methods that return multiple items: getMany(), getRange(), getAll(), find(), findAll(), query(), queryAny(), etc. Internally, all of these methods that return multiple items have a loop that calls get() repeatedly, as they aggregate the individual items to return. A simplified example: public function get($key){ return $this->collection[$key];

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

一世执手 提交于 2019-12-04 05:32:36
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 detect the types that far and go beyond the type constraint! Then why doesn't it go beyond the type

Overriding Javascript Confirm() while preserving the callback

旧时模样 提交于 2019-12-04 05:22:44
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 . submit returns true and cancel returns false. But now, how do I return either true or false based on

Access specifier while overriding methods

做~自己de王妃 提交于 2019-12-04 05:03:31
Assume you have a class that defines virtual methods with the access specifier public. Can you change the access specifier on your overriden methods? I am assuming no. Looking for an explanation. Uri Yes you can, but it "doesn't grok". Take a look at Overriding public virtual functions with private functions in C++ The answer is: sort of. You can only change the access of members the derived class has access to. The type of inheritance has no effect - this only controls the default access for inherited members (to a point, following other rules). So, you can make a base class's protected

C++ Overriding Methods

雨燕双飞 提交于 2019-12-04 04:26:33
I can't figure out what is up with this. I have a Scene class that has a vector of Entities and allows you to add and get Entities from the scene: class Scene { private: // -- PRIVATE DATA ------ vector<Entity> entityList; public: // -- STRUCTORS --------- Scene(); // -- PUBLIC METHODS ---- void addEntity(Entity); // Add entity to list Entity getEntity(int); // Get entity from list int entityCount(); }; My Entity class is as follows (output is for testing): class Entity { public: virtual void draw() { cout << "No" << endl; }; }; And then I have a Polygon class that inherits from Entity: class

How to pass variables to overridden toString() method?

和自甴很熟 提交于 2019-12-04 04:20:16
问题 Is it possible to pass in a bool variable into an overridden toString() method, so it can conditionally print the object in different formats? 回答1: You can define overload method of ToString() . public string ToString(bool status){ // } 回答2: The typical pattern for parametrized ToString() is to declare an overload with a string parameter. Example: class Foo { public string ToString(string format) { //change behavior based on format } } For a framework example see Guid.ToString 回答3: If you are

Extend magento core controller (Checkout/OnepageController)

有些话、适合烂在心里 提交于 2019-12-04 04:14:43
问题 I am having problems while overriding a core controller. I want to add a new function but it only works if I do it in the core file (code/core/checkout/controllers/onepagecontroller.php). I have followed some post, but it's not working. Some of them are: http://www.magentocommerce.com/boards/viewthread/32979/P0/ http://www.webspeaks.in/2011/03/override-controllers-in-magento.html www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a

Inherit from jQuery UI dialog and call overridden method

≯℡__Kan透↙ 提交于 2019-12-04 04:02:55
The simple code below describes my question (at least I hopse so): $.widget("ui.mydialog", $.ui.dialog, { _create: function() { // How to call _create method of dialog? } }); I tried to call $.ui.dialog.prototype._create() from within the above create method, but get the below error in Firebug: this.element is undefined this.originalTitle = this.element.attr('title'); jquery...5667348 (line 5864) How else can I call that "super" method? jQuery UI version 1.8.8 I guess I just found a solution ... $.ui.dialog.prototype._create.call(this); The full code: $.widget("ui.ajaxdialog", $.ui.dialog, {

overriding a global function in javascript

妖精的绣舞 提交于 2019-12-04 03:55:25
I am trying to add my own error handling to the JavaScript setTimeout function. The following code works fine in chrome: var oldSetTimeout = window.setTimeout; window.setTimeout = function setTimeout(func, delay) { var args = Array.prototype.slice.call(arguments, 0); args[0] = function timeoutFunction() { var timeoutArgs = Array.prototype.slice.call(arguments, 0); try { func.apply(this,timeoutArgs); } catch (exception) { //Do Error Handling } } return oldSetTimeout.apply(this, args); } But in IE7 it turns into a recursive function. For some reason oldSetTimeout gets set to the new function.