30,457 questions
-6
votes
1
answer
98
views
Wrapping a method in a try-catch block but unsure where to declare a char variable
I have this method in my program, it is meant to register the gender of the user for later on in the program (with Male and Female as the only valid options):
public static void Main(string[] args)
{
...
-6
votes
1
answer
84
views
Formatting the first symbol of a string to be upper case - a private method or formatting on the go?
In a class that has a bunch of functions, should I be making a separate private method specifically for formatting or should I just be formatting in every function that requires a string to be ...
3
votes
1
answer
66
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
63
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
201
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
152
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
75
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
95
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
124
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
42
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
146
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
113
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
69
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
66
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
115
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
57
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
102
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) ...
1
vote
0
answers
79
views
What is the best method return type to support my PowerShell cmdlets
I have created a module with a custom class that generates specific [Node] objects. The module has another class with an method that gets a single specific Node and also a method that gets a ...
0
votes
0
answers
27
views
When i call the onCreate, onCreateOptions menu, OnOptionItemsSelected in fragment class(for example: To add a menu item(refresh)
/*
* ForecastFragment
*/
public class ForecastFragment extends Fragment {
//------------------------------
//---- DATA MEMBERS ----
//--------------------...
1
vote
1
answer
116
views
NetBeans is glitching and calling a method that isn't there
I'm doing homework for a Data Structures class and making a 2-3 tree in NetBeans, but there's a glitch that keeps happening where a method is called twice, but the second time, it's being called by a ...
0
votes
3
answers
141
views
How do I give the possibility to call multiple optional methods onto one parameter in a constructor in JAVA
I would like to make a constructor with an optional parameter, to avoid giving in Strings all the time, because I need to use the constructor like a thousand times, so I would like to call methods ...
-2
votes
2
answers
93
views
How do I call the method from a class that creates other objects? [closed]
I have five classes. My Main class, a form class, two subclasses that extend the form class and a createForm class I am forced to use to create new instances of the subclass.
public class FormenFabrik ...
0
votes
1
answer
176
views
Intercepting and redirecting calls of a nested class structure in python
I have a very deeply nested class structure spanning multiple files and multiple levels of definitions. You can imagine this as a class describing some hardware system where each hardware component is ...
-3
votes
4
answers
122
views
Needed Aid With Java Schoolwork - Containing Arrays & Array Searchs
Current Outputs:
Is [1, 2, 3] found in [1, 2, 1, 2, 3] ? >>> false
Is [1, 1, 3] found in [1, 2, 1, 2, 3] ? >>> false
Needed Outputs:
Is [1, 2, 3] found in [1, 2, 1, 2, 3]? >>&...
1
vote
2
answers
57
views
Laravel error whit undefinde variables pass to view
im new to laravel and im getting an error Undefined variable $columnCounts passed to view.
i have a index() method that call 2 other method of the same NumberController, columnCount() and rowCount() ...
-1
votes
1
answer
80
views
I'm making a Guess a Number Game in Java Swing and I'm having problems the JButton [duplicate]
The program technically works, but I keep getting the error:
"Cannot invoke "javax.swing.JButton.addActionListener(java.awt.event.ActionListener)" because "this.check" is null&...
0
votes
0
answers
51
views
Jacobi method converges faster than Gauss-Seidel in case of Laplace equation
It is need to solve the problem using the Jacobi method: d^T/dx^2 + d^2T/dy^2 = 0 with conditions at the boundaries of the square:
T(0, y) = 1, T(x, 1) = 1, dT/dx(1, y) = 1 - y, dT/dy(x, 0) = x.
...
1
vote
1
answer
108
views
Why can't I add default-argument to my lambda function parameters (or is there an alternative way to do it)?
So I have a method with simple lambda functions I use to update my weights and I want to try different functions but I also want to have default parameter for the decay:
void ema_update(int i, const ...
-4
votes
1
answer
163
views
Unexpected behavior of Global Scope Variable in C#
I have been trying to understand two code blocks.
The first code block:
string status = "Healthy";
Console.WriteLine($"Start: {status}");
SetHealth(status, false);
Console....
0
votes
0
answers
39
views
JS `os` method not returning any data in Vite project
My goal is to collect and graph CPU usage for the host. I have a simple Vite project and am using vite-plugin-node-polyfills to try to use the os JS method. However, it just returns an empty object. I ...
-2
votes
1
answer
78
views
In Python, how can I find the class in which a method is defined? [duplicate]
If I have a class hierarchy in Python (we can assume there's no multiple inheritance), how can I find the class in which a method is defined? For example:
class C:
def f(): pass
class D(C):
...
-4
votes
1
answer
78
views
Creating a bubblesort method to sort a list in C# [closed]
I seem to have a problem to sort my list (cities and temperatures) from coldest to warmest. Here is the code for the method.
static void bubblesort(List<Stad> städer, int n)
{
n = städer....
1
vote
2
answers
79
views
How to set values of matrices with the help of methods in c?
Ive been trying to set the values of matrices with the help of methods that take pointers, But I am unable to do this. The setMatrixValue method stops working when the loop reaches the second row. The ...
0
votes
1
answer
117
views
How can I use a method outside of a class without using static keyword in C#?
I'm beginner in C# programming,
What I want to do is use a method out side of the class but method is unreachable, I cant do it without static keyword and I dont want to use static keyword because I'm ...
1
vote
1
answer
108
views
SwiftUI onDelete() need the row ID from the IndexSet
I'm trying to use SwiftUI with onDelete() method to capture the TodoItem.id of the row that was swiped. I've set up an array called arrayOfTodosToDelete which will be the IDs of the deleted rows ie [&...
0
votes
0
answers
29
views
vectorize returns 0s instead of results
The MWE below shows that vectorize returns zeros instead of the actual values. Compare the printout from within the function to the arrays returned in the second test. It is curious that the first ...
1
vote
1
answer
67
views
Trying to decipher what this code does and why [PANDAS] (astype method)
So I'm an economics undergrad trying to learn some pandas for data manipulation.
# Making YEAR as the index
inflation_forecasts.index = pd.DatetimeIndex(inflation_forecasts['YEAR'].astype(int).astype(...
3
votes
3
answers
218
views
In C++, is there a way to provide object member name as template parameter?
I have multiple classes C1, C2, etc, each has different members variables, ex: C1M1, C1M2, C2N1, C2N2. And I have a pointer to data that could be an object of C1, C2 based on initial bytes.
Is there a ...
2
votes
1
answer
107
views
Issue with recursive method to extract substring between outer parentheses
I'm working on a recursive method clean that extracts the substring inside the outermost parentheses of a string, without the parentheses themselves. The method works as expected, but omits the ...
1
vote
0
answers
27
views
How come the clip.getLevel(); method is only returning -1.0?
I am trying to make an audio visualizer on Java, and I am attempting to use the .getLevel() function of the Clip clip; thing. Yet it is only returning -1.0, nothing else. Here is my code:
import java....
0
votes
2
answers
146
views
Why C# Error CS0103 when calling a method from another namespace when the namespace was rightly specified?
I created an age conditional "Hello World!". You type in your name, then I ask your age and if you're under 8, I ask you to leave the computer because you should just go play outside.
Here's ...
-4
votes
2
answers
103
views
Return values beside each other
I've been assigned a temperature conversion assignment that requires values to be printed next to each other, using two static methods and a single System.out.print statement. For reference, I've ...
-1
votes
1
answer
188
views
Make the code from a WooCommerce Payment Plugin HPOS Compatible [closed]
I'm trying to make a plugin HPOS compatible.
Below is the new code that I edited and then the old one.
This is my code attempt (new replaced code):
/**
* Save payment info
*
* @param type $order_id
...
1
vote
0
answers
79
views
How to highlight a specific IME in ACTION_INPUT_METHOD_SETTINGS for android
When I call the android settings menu to enable my input method, I would like the menu to flash to highlight the correct item in the list for my keyboard. I saw this happen when installing another ...
0
votes
1
answer
59
views
How to get a function call argument string name, inside the same function. Using that as "extra parameter", avoiding adding an extra parameter [duplicate]
Having any Python function as:
def function1(param1, param2):
#...
return 0
How would be possible to get a param string name (variable name) used in the function call? ideally getting this ...
0
votes
1
answer
55
views
Why can if statement works using an object (like Map) with ".has()" and no working with ".includes"? [closed]
That's my code to explain my idea better (I'm a non english speaker):
The ".includes()" method doesn't work in this case
const sentence = "hello world hello boy";
let words = ...
1
vote
0
answers
49
views
In Django are updates of dict within a form class from a view persistent for all users? [duplicate]
I use Django 5.1.2
In order to clarify what my users need to do when my app serves them a form, I've added a dict to my forms called 'contents'. It contains a bunch of instructions for the template ...
0
votes
1
answer
70
views
Is it possible to change the return type of a method based on what is passed in as a parameter? [duplicate]
Is it possible for the same method have different return types based on what is passed in, so that for example GetScripts(new Camera()) returns a Camera and GetScripts(new Cube()) returns a Cube?
I ...
0
votes
1
answer
74
views
Coq Error Syntax error: '.' expected after [gallina] (in [vernac_aux])
So I have this code:
Require Import Unicode.Utf8.
Require Import String.
Inductive AExp :=
| avar : string → AExp
| anum : nat → AExp
| aplus : AExp → AExp → AExp
| amul : AExp → AExp → AExp.
...
0
votes
0
answers
47
views
My Angular HTML Page doesn't load after populating ng2-chart datasets' data
I'm currently working on an Angular project to develop a dashboard of sorts.
public donutChartData: any = {
labels: [],
datasets: [
{
data: [1, 1, 1],
backgroundColor: [
...