30,457 questions
3
votes
1
answer
54
views
Typescript method overload lost
I'm using typescript in a project which uses BackboneJS and in a certain case, a method overload gets lost.
I narrowed it down to this case:
class Model {
set<A extends string>(key: A, value: ...
0
votes
1
answer
59
views
How can I forbid method redefenition in TCL OO class?
I would like that method redefenition would result in failure and script execution stop. Like any other common error.
In the following example I want to see that method print cannot be redefined.
oo::...
3
votes
1
answer
198
views
What does 0 mean in someList.toArray(new AnotherClass[0])?
In Java we have toArray() method which will return Object[]. If I want to return another data type I need to pass it to parameters like this
SomeClass.SomeList.toArray(new AnotherClass[0]);
What does ...
0
votes
0
answers
146
views
Detect unimplemented class methods without a program failing to link
Suppose I am working on a library with a decent number of classes, most of them having a bunch of methods, in addition to the basic ctors and dtor. For reasons, the method implementations are spread ...
1
vote
1
answer
64
views
How to type class method arguments based on function arguments passed to class constructor
I have class example:
export class Test{
private func: (...args: any[]) => void;
constructor(func: (...args: any[]) => void) {
this.func = func;
}
method(...args: any[]) {...
0
votes
1
answer
94
views
PHP vs C++: How do I declare class constants which are used in method calls in C++? [duplicate]
I come from PHP where I usually never have global constants. For instance, if I have the class Users and the method add(int $status, string $username) then the status of the user is a constant only ...
0
votes
3
answers
116
views
Minifiying javascript file with webpack breaks vue functionality (specifically with method calls on class instance)
I am working on an ASP.NET project that uses Vue.js and jQuery. I have a JavaScript file (fields.js) that defines several classes (e.g., Users, Fields) and initializes a Vue instance. When I use the ...
0
votes
0
answers
41
views
What does this reduce() function do in counting elements from an array? [duplicate]
I'm trying to understand how the reduce() function works in this example:
const fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple'];
const count = fruits.reduce((tally, fruit) => {
...
-9
votes
1
answer
140
views
Using the .find() function in a loop [closed]
I was trying to get the last word of the sentence using the .find() method in a loop.
My code:
sentence = "please write a program which keeps asking the user for words"
index = 0
substring = ...
0
votes
2
answers
102
views
Adding decorator to a python class
I have a few methods that require a certain condition to be applied to function properly. To avoid code repetition I've created a decorator to check if this condition is applied and only then execute ...
2
votes
1
answer
64
views
How to pass any object as a classmethod's first argument - circumvent injection of class argument
Passing a class, or a totally different object, as the first argument to method is easy:
class Foo:
def method(self): ...
Foo.method(object()) # pass anything to self
I wonder, is this possible ...
1
vote
1
answer
64
views
Methods for a TypeScript type alias
I have this Dir type alias that is a set of 8 cardinal directions, used as an enum:
type Dir = "N" | "NE" | "E" | "SE" | "S" | "SW" | "...
0
votes
1
answer
110
views
How to define a templated method declared in a templated parent?
// StopOrderBase.hpp
template <typename TriggerOrderType>
struct StopOrderBase {
template <typename OrderBook>
bool execute(OrderBook& orderbook) const noexcept;
};
// ...
0
votes
1
answer
52
views
Two Separate struct Methods Modifying another Struct Field [duplicate]
I want to know how two separate struct methods can modify a field in third struct.
What I'm getting now is {[20]}
{[30]}
Like the two methods on B and C should modify the list field of A and the ...
1
vote
2
answers
100
views
How can I calculate 0 factorial in a basic factorial code in Java
Here is a basic Java Code which I wrote. I want to know how I can calculate 0! as it can calculate every other number.
import java.util.*;
public class main {
public static int calcFactorial(int n) ...