overriding

override on non-virtual functions

旧时模样 提交于 2019-11-28 08:04:56
The C++11 FDIS it says If a virtual function is marked with the virt-specifier override and does not override a member function of a base class, the program is ill-formed. [ Example: struct B { virtual void f(int); }; struct D : B { void f(long) override; // error: wrong signature overriding B::f void f(int) override; // OK }; What if B::f would not have been marked virtual? Is the program ill-formed, then? Or is override then to be ignored`. I can not find any handling of this case in the std text. Update 1/2 (merged) I forwarded a request to the C++ Editors to look into things. Thanks

How to prevent derived class from making a private/protected virtual function public?

时间秒杀一切 提交于 2019-11-28 08:01:07
问题 There are good reasons for constructing the base class interface with all virtual functions as private or protected (see this). But then how does one prevent the derived classes (which may be in the hands of external clients) from making the private virtual function as public? In Virtually Yours, the authors talk about this problem, but no solution is discussed. Edit : From your answers and as I previously thought, it seems there is no way to prevent this. But since in this situation, it is

Resolving property and function “overrides” in QML

懵懂的女人 提交于 2019-11-28 08:00:50
问题 It seems like although QML supports "overriding" of properties and functions, the support is somewhat clunky. Here is an example snippet: // T1.qml QtObject { property int p: 1 function f() { return 1 } } // T2.qml T1 { property string p: "blah" function f() { return "blah" } } // usage T1 { Component.onCompleted: { var obj = this for (var k in obj) console.log(k + " " + typeof obj[k] + " " + obj[k]) } } T2 { Component.onCompleted: { var obj = this for (var k in obj) console.log(k + " " +

Override of toString() that makes use of the overridden toString()

我的梦境 提交于 2019-11-28 07:44:19
问题 Basically this is what I am trying to achieve. classname@address(?)[original toString() ], object's name, object's age @Override public String toString() { return String.format("%s , %s , %d", this.toString(), this.getName(),this.getAge()); } Problem, toString() gets called recursively. I can't call super.toString() because that's not what I want. I want ' this ' to call the original toString() . This this.super.toString() doesn't work for obvious reasons. I'm running out of steam, can this

Best practices regarding equals: to overload or not to overload?

笑着哭i 提交于 2019-11-28 07:20:23
Consider the following snippet: import java.util.*; public class EqualsOverload { public static void main(String[] args) { class Thing { final int x; Thing(int x) { this.x = x; } public int hashCode() { return x; } public boolean equals(Thing other) { return this.x == other.x; } } List<Thing> myThings = Arrays.asList(new Thing(42)); System.out.println(myThings.contains(new Thing(42))); // prints "false" } } Note that contains returns false !!! We seems to have lost our things!! The bug, of course, is the fact that we've accidentally overloaded , instead of overridden , Object.equals(Object) .

Windows Phone 8.1 override back button on a certain page

此生再无相见时 提交于 2019-11-28 07:06:19
I am developing a WP 8.1 XAML app. The first page is a login page, the second for example a history page. There will be more pages, but it doesn't matter at the moment. When I press the login button on the login page, the second (history) page appears. If I press the (physical) back button on the history page, it goes back to the login page. But I would like to disable this function. Instead of this I would like when I press the back button a MessageDialog appears and if I press again within a few seconds (for example 3 secs) the app terminates. I tried to find the answer for my questions, but

AppleLanguages value overrides the value of language set in IOS settings preferred language

我们两清 提交于 2019-11-28 06:51:49
问题 I am working on Localization of my app that supports both spanish and English languages.These options are listed in a tableview.On clicking English i am setting the value "en" for the key "AppleLanguages" in NSUserDefaults.So that it can show the content in English. NSUserDefaults *nsdefault=[NSUserDefaults standardUserDefaults]; [nsdefault setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"]; [nsdefault synchronize]; Also at the same time i am trying to fetch the Language

Override Default Constructor of Partial Class with Another Partial Class

拟墨画扇 提交于 2019-11-28 06:41:30
I don't think this is possible, but if is then I need it :) I have a auto-generated proxy file from the wsdl.exe command line tool by Visual Studio 2008. The proxy output is partial classes. I want to override the default constructor that is generated. I would rather not modify the code since it is auto-generated. I tried making another partial class and redefining the default constructor, but that doesn't work. I then tried using the override and new keywords, but that doesn't work. I know I could inherit from the partial class, but that would mean I'd have to change all of our source code to

Override window.open()

对着背影说爱祢 提交于 2019-11-28 06:16:08
问题 I'm trying to override window.open() , so I'm trying to find a way to open link in new window without window.open() . In detail, I'm in such a situation: I've got a Silverlight Web Part Which uses HTMLWindow.Navigate() to open hyperlinks in new window, so I cannot use <a> because I've got totally no control to the Web part. The only way is to override window.open() . For example, when I want to open link in the top window, I override window.open() like this: window.open = function (open) {

Swift: Overriding == in subclass results invocation of == in superclass only

谁说胖子不能爱 提交于 2019-11-28 05:50:17
I've got a class A , which conforms to Equatable protocol and implements == function. In subclass B I override == with more checks. However, when I do comparison between two arrays of instances of B (which both have type Array<A> ), == for A is invoked. Of course if I change type of both arrays to Array<B> , == for B is invoked. I came up with the following solution: A.swift: internal func ==(lhs: A, rhs: A) -> Bool { if lhs is B && rhs is B { return lhs as! B == rhs as! B } return ... } Which looks really ugly and must be extended for every subclass of A . Is there a way to make sure that ==