overriding

In C++, is a function automatically virtual if it overrides a virtual function?

自古美人都是妖i 提交于 2019-11-27 21:15:10
I would expect that if foo is declared in class D , but not marked virtual, then the following code would call the implementation of foo in D (regardless of the dynamic type of d ). D& d = ...; d.foo(); However, in the following program, that is not the case. Can anyone explain this? Is a method automatically virtual if it overrides a virtual function? #include <iostream> using namespace std; class C { public: virtual void foo() { cout << "C" << endl; } }; class D : public C { public: void foo() { cout << "D" << endl; } }; class E : public D { public: void foo() { cout << "E" << endl; } }; int

Override a member function with different return type

梦想与她 提交于 2019-11-27 20:33:18
Consider the example below: #include <iostream> using namespace std; class base { public: virtual int func() { cout << "vfunc in base class\n"; return 0; } }; class derived: public base { public: double func() { cout << "vfunc in derived class\n"; return 0; } }; int main() { base *bptr = new derived; bptr->func(); return 0; } The compiler gives an error for the above code that there is conflicting type for the overriden function. Why is it not possible to override a function in the derived class with a different return type ? I believe, in-order to override a function, the base class virtual

How are C# Generics implemented?

梦想与她 提交于 2019-11-27 20:16:08
I had thought that Generics in C# were implemented such that a new class/method/what-have-you was generated, either at run-time or compile-time, when a new generic type was used, similar to C++ templates (which I've never actually looked into and I very well could be wrong, about which I'd gladly accept correction). But in my coding I came up with an exact counterexample: static class Program { static void Main() { Test testVar = new Test(); GenericTest<Test> genericTest = new GenericTest<Test>(); int gen = genericTest.Get(testVar); RegularTest regTest = new RegularTest(); int reg = regTest

How can I define a custom equality operation that will be used by immutable Set comparison methods

时间秒杀一切 提交于 2019-11-27 19:58:56
I have an immutable Set of a class, Set[MyClass], and I want to use the Set methods intersect and diff, but I want them to test for equality using my custom equals method, rather than default object equality test I have tried overriding the == operator, but it isn't being used. Thanks in advance. Edit: The intersect method is a concrete value member of GenSetLike spec: http://www.scala-lang.org/api/current/scala/collection/GenSetLike.html src: https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_1_final/src//library/scala/collection/GenSetLike.scala#L1 def intersect(that: GenSet[A]):

Overriding a stored property in Swift

☆樱花仙子☆ 提交于 2019-11-27 19:33:55
I noticed that the compiler won't let me override a stored property with another stored value (which seems odd): class Jedi { var lightSaberColor = "Blue" } class Sith: Jedi { override var lightSaberColor = "Red" // Cannot override with a stored property lightSaberColor } However, I'm allowed to do this with a computed property: class Jedi { let lightSaberColor = "Blue" } class Sith: Jedi { override var lightSaberColor : String{return "Red"} } Why am I not allowed to give it another value? Why is overriding with a stored property an abomination and doing it with a computed one kosher? What

Javascript: Overriding XMLHttpRequest.open()

橙三吉。 提交于 2019-11-27 19:30:18
How would I be able to override the XMLHttpRequest.open() method and then catch and alter it's arguments? I've already tried the proxy method but it didn't work, although removing the open over-rid when XMLHttpRequest() was called: (function() { var proxied = window.XMLHttpRequest.open; window.XMLHttpRequest.open = function() { $('.log').html(arguments[0]); return proxied.apply(this, arguments); }; })(); You are not modifying the open method inherited by XMLHttpRequest objects but just adding a method to the XMLHttpRequest constructor which is actually never used. I tried this code in facebook

Can I get Java 5 to ignore @Override errors? [duplicate]

怎甘沉沦 提交于 2019-11-27 19:28:54
问题 Possible Duplicate: Why does Eclipse complain about @Override on interface methods? I have some Java code that was written using Eclipse and the Java 6 SDK, so methods that implement an interface are annotated with @Override - an annotation that is legal in Java 6, but not in Java 5. I'd like to compile the same code using the Java 5 SDK ( javac on Mac OS X 10.5). Everything compiles and runs fine except for the @Override annotations. Is there any way I can get javac to ignore the @Override

Overriding css style?

三世轮回 提交于 2019-11-27 19:21:44
I look on Stack Overflow, and didn't find the solution, I know how to override style if style exists, just change its property. But now I have a strange style to override Here is an example of what I have First I have this one: .slikezamenjanje img{ max-width: 100%; max-height:150px; padding-right:7px; } Now I need to override that style with just this one: #zoomTarget .slikezamenjanje img { max-width: 100%; } The problem is that first style appends second, but I don't want that, in this second style what I need is just one line, not to append from the first style? Instead of override you can

Rails: Overriding ActiveRecord association method

蓝咒 提交于 2019-11-27 19:00:24
Is there a way to override one of the methods provided by an ActiveRecord association? Say for example I have the following typical polymorphic has_many :through association: class Story < ActiveRecord::Base has_many :taggings, :as => :taggable has_many :tags, :through => :taggings, :order => :name end class Tag < ActiveRecord::Base has_many :taggings, :dependent => :destroy has_many :stories, :through => :taggings, :source => :taggable, :source_type => "Story" end As you probably know this adds a whole slew of associated methods to the Story model like tags, tags<<, tags=, tags.empty?, etc.

Force a class to override the .equals method

两盒软妹~` 提交于 2019-11-27 18:41:30
I have a bunch of class who implement a common interface : Command. And this bunch of class goes to a Map. To get the Map working correctly, I need to each class who implements Command to override the Object.equals(Object other) method. it's fine. But i whould like to force the overriding of equals. => Have a compilation error when something who implement command dont override equals. It's that possible ? Edit : BTW , i will also need to forcing the override of hashcode... No, you can't. What you can do, however, is use an abstract base class instead of an interface, and make equals() abstract