subclassing

A line-based thread-safe std::cerr for C++

风流意气都作罢 提交于 2019-11-30 23:53:26
What is the easiest way to create my own std::cerr so that it is line-by-line thread-safe. I am preferably looking for the code to do it. What I need is so that a line of output (terminated with std::endl ) generated by one thread stays as a line of output when I actually see it on my console (and is not mixed with some other thread's output). Solution : std::cerr is much slower than cstdio. I prefer using fprintf(stderr, "The message") inside of a CriticalSectionLocker class whose constructor acquires a thread-safe lock and the destructor releases it. If available, osyncstream (C++20) solves

Why can't I use a subclass of a generic type in Swift?

有些话、适合烂在心里 提交于 2019-11-30 20:11:02
Why doesn't Swift allow me to assign value Foo<U> to a variable of type Foo<T> , where U is a subclass of T? For example: class Cheese { let smell: Int let hardness: Int let name: String init(smell: Int, hardness: Int, name: String) { self.smell = smell self.hardness = hardness self.name = name } func cut() { print("Peeyoo!") } } class Gouda: Cheese { let aged: Bool init(smell: Int, hardness: Int, name: String, aged: Bool) { self.aged = aged super.init(smell: smell, hardness: hardness, name: name) } override func cut() { print("Smells delicious") } } class Platter<Food> { var food: Food init

Required initializers for a subclass of UIViewController

本小妞迷上赌 提交于 2019-11-30 18:43:08
I've been attempting to follow a tutorial about creating a container view controller. It's in Objective-C. I want to convert it to Swift. I've found some of the same questions here, but I didn't get too much out of them. Here's the code. import UIKit class ContainerViewController: UIViewController { // Class "ContainerViewController" has no initializers - That I know why. // 'required' initializer 'init(coder:)' must be provided by a subclass of UIViewController var currentDetailViewController: UIViewController override func viewDidLoad() { super.viewDidLoad() } override func

A line-based thread-safe std::cerr for C++

廉价感情. 提交于 2019-11-30 18:05:55
问题 What is the easiest way to create my own std::cerr so that it is line-by-line thread-safe. I am preferably looking for the code to do it. What I need is so that a line of output (terminated with std::endl ) generated by one thread stays as a line of output when I actually see it on my console (and is not mixed with some other thread's output). Solution : std::cerr is much slower than cstdio. I prefer using fprintf(stderr, "The message") inside of a CriticalSectionLocker class whose

How to override a superclass' property with more specific types?

不羁岁月 提交于 2019-11-30 13:39:56
问题 The Scenario I have a situation where a base class called AbstractRequest has a delegate property of type id <AbstractRequestDelegate> declared in the header file: @property (nonatomic, assign) id <AbstractRequestDelegate> delegate; The abstract delegate protocol contains a few required methods, and as indicated with the word 'abstract', both the AbstractRequest and the AbstractRequestDelegate are intended to be subclasses/extended. One example of this would be the subclass ConcreteRequest

What is subclassing?

百般思念 提交于 2019-11-30 11:51:22
I am new to java and I am trying to create an XML document and clone a specific node (minus the textnode) of this document over and over again. Someone answered me and said that I should subclass the node and override the cloning. So my question is what is sub-classing? @Charlie Martin has explained what subclassing means. However, it is not clear that you've been given good advice. If you are creating the XML document by assembling a DOM in memory, a better approach would be to create a helper class with static methods that perform the sequence of DOM node operations that you need to do.

Making a thinner UITabBar

你说的曾经没有我的故事 提交于 2019-11-30 07:42:21
I would like to be able to thin the UITabBar's height by removing each item's titles and reclaiming the vertical space they take up, a la Tweetie 2. This doesn't seem settable in the .xib or programmatically. Will I have to subclass the UITabBar and roll my own? Roll your own. I'm sure Tweetie 2's is custom; and the height is set in the handed down UITabBar. You can achieve a similar effect by placing a segmented control inside a uitoolbar. I did this and it looks quite nice. 来源: https://stackoverflow.com/questions/1563701/making-a-thinner-uitabbar

How to cast 'Class A' to its subclass 'Class B' - Objective-C

拥有回忆 提交于 2019-11-30 06:46:00
问题 I'm using a framework which defines and uses 'ClassA', a subclass of NSObject. I would like to add some variables and functionality so naturally I created 'ClassB', a subclass of 'ClassA' Now my problem is this. Many of the methods within this framework return instances of 'ClassA' which I would like to cast to my subclass. For example take this method: - (ClassA *)doSomethingCool:(int)howCool Now in my code I try this: ClassB * objB; objB = (ClassB *)doSomethingCool(10); NSLog(@"objB

Why can't I use a subclass of a generic type in Swift?

那年仲夏 提交于 2019-11-30 03:55:58
问题 Why doesn't Swift allow me to assign value Foo<U> to a variable of type Foo<T> , where U is a subclass of T? For example: class Cheese { let smell: Int let hardness: Int let name: String init(smell: Int, hardness: Int, name: String) { self.smell = smell self.hardness = hardness self.name = name } func cut() { print("Peeyoo!") } } class Gouda: Cheese { let aged: Bool init(smell: Int, hardness: Int, name: String, aged: Bool) { self.aged = aged super.init(smell: smell, hardness: hardness, name:

Is subclassing a User model really bad to do in Rails?

≡放荡痞女 提交于 2019-11-30 03:09:35
问题 I am getting lots of push back from Rails because I have subclassed User into many different subclasses. In my application, not all users are equal. There's actually a lot of model objects and not every User type has access to them. I also need a way to do polymorphic behaviour. For example, many methods will behave differently depending on the type. Isn't that what polymorphism is for? But the thing is, I am always getting push back from Rails. The defaults - especially the way forms submit