Questions tagged [return-type]
is for questions dealing with the type of the variable or value returned by a function.
1,402
questions
-1
votes
1
answer
25
views
Class method returns None
I did a few modifications to the Bellman-Ford to get some data I need to compare but I can't seem to be able to get some of the information I need from the return the PrintArr method, while it prints ...
-1
votes
0
answers
33
views
Trying to clean up my main.cpp by relying more on classes: Trouble with alternate loop positioning
I am trying to practice my coding by streamlining my Main.cpp while letting my classes perform the majority of the tasks that I need. I have included two variations of the same program below: Main.cpp,...
0
votes
0
answers
36
views
PHP function return value of exception or none
PHP 8 brought many nice features, one being union types for return values of functions.
One issue I am sitting with, where I can not use the union types declaration, is when I either want to return a ...
-2
votes
2
answers
75
views
I'm having trouble grasping what specifically the return type is to a function [closed]
As far as I know now, a function has 4 parts, one of them being a return type.
Main returns an int, but to who? Like, on a deeper level, I guess who is the caller, or who is return talking to?
I get ...
1
vote
1
answer
32
views
cpp - alias for member functions` return types
I've been watching this CppCon talk where the speaker was talking about writing classes resistant to future changes. He provided the following code as an example (that I show here abridged):
template&...
0
votes
3
answers
77
views
why does returning the local variable address throws an error but returning the local variable value don't? [duplicate]
I can not understand, what is the difference between following function bodies
int func(void){
int A = 20;
return A;
}
and
int* func(void){
int A = 20;
return &A;
}
why returning ...
0
votes
1
answer
40
views
Typescript - exact return type of function
I have a problem with return type of the function. In the example, if I explicitly define return type Foo, it shows error as expected. If I add type to function, an error is not shown.
It seems that ...
0
votes
1
answer
37
views
How can I search an element in an array with strcmp
Animal is a struct and name is one of its attribute.
What I want is when I write a name in scanf, it should iterate in the array uing strcmp and when it returns 0 then it should print that index in ...
0
votes
1
answer
27
views
Trouble getting and printing a returned value from one class to another in Java
I'm trying to import data from a CSV file. I don't have any issue about the importing process. But, when I'm passing an imported array from the CSV file to another method in another class, I can not ...
0
votes
1
answer
38
views
How to return more than one integer values with a return statement in a user-defined method with integer return type in C#? [duplicate]
namespace MyApp
{
class Program
{
static int check(int id, int age)
{
return id,age; // adding age gives error
}
public static void Main(string[] ...
-1
votes
2
answers
66
views
public int Continue() : (Not all code paths return a value)
I have written this function to use it into another class, but code generates an error and says,
Not all code paths return a value.
I also tried to search the solution regarding this problem and most ...
-7
votes
2
answers
86
views
What actually is int in int main void in c? [duplicate]
#include<stdio.h>
#include<conio.h>
int main(){
printf("hello world");
}
What actually does int do to the main function? Is it similar to the data type int? What does conio....
0
votes
2
answers
58
views
How do I make my function return different results depending on type it's been called using templates in C++
I've been looking for quite a while for an answer to my question, but couldn't find anything that worked.
Basically, I have a Binary Search Tree and a Search function:
T BinarySearchTree::Search(Node *...
0
votes
0
answers
20
views
Can a member function in a class return complex objects such as `const char **` or a dynamic array? [duplicate]
Issue
Assume that I have a dynamic array object that stores strings and a data object for storing
a person's name and data record.
Note:
The data record uses the dynamic array object.
// :: normal ...
0
votes
1
answer
58
views
C#: How to return optional ref to struct
In C# how do I write a function that may or may not return a ref to a struct?
What I basically want is a return type Nullable<ref OutboxSlot> but the compiler complains about ref beeing an ...
2
votes
2
answers
101
views
Dynamic return type based on input argument type
I'm trying to write a small function that takes two lists and sorts one based on the elements of the other. So something like:
List<Integer> keys = Arrays.asList(3, 5, 2, 4, 1);
List<String&...
1
vote
1
answer
38
views
2D Array malloc - only last Items are shown
I want to malloc a 2d array and put data from a file in it.
But it only shows the last items of my file.
What do I have to do?
The file has 600.000 numbers like "280.000" in it.
double ...
0
votes
2
answers
65
views
How do I return a char from a char pointer function in C?
i recently made a function that finds the smallest character in a string. I am not sure how to return the smallest character in a char pointer function.
#include <stdio.h>
#include <string.h&...
2
votes
0
answers
28
views
Generic React/Typescript function has function in props but does not detect return type when param added
Guys I have no idea what title to put for this question, but here is my problem: I'm trying to add typescript restrictions nested many levels deep for react components and contexts.
I've distilled my ...
0
votes
0
answers
100
views
SonarLint Refactor function to Always return same type : different var types
Hi I have pieces of code
Where in a function is exported as a module and inside it we are validating some conditions.
If(title)
return true;
else
return 'message'
This gives off as error in sonar to ...
0
votes
1
answer
49
views
commun types between two parameter pack C++
I need to define the return types (???? in code) after a sum with 2 parameters pack! My objective is to define a Tuple class (like std::tuple) and to implement for example here, the addition between ...
0
votes
1
answer
32
views
Type of returned value in SPARQL Query
Is it possible to know the type of the return values in a SPARQL query?
For example, is there a function to define the type of ?x ?price ?p
in the following query?
SELECT DISTINCT ?x ?price ?p
...
1
vote
2
answers
112
views
Typescript class method return type based on parameter
I am trying to create a class with a method whose return type will depend on the boolean value of a flag-parameter
I have managed to do this successfully when
using a plain function expression that ...
-2
votes
1
answer
68
views
Return a List<List<E>> in Java
i have to write a method that return the same type as in title.
But as you all know, List is an interface, and therefore has no instance.
In my code, i use 'ArrayList<ArrayList>listList' to ...
0
votes
2
answers
89
views
Generic Return Types
Would there be a better way to write this getInput() method instead of checking for every single class that could be passed in?
public Object getInput(String prompt, Class<?> type) {
...
0
votes
0
answers
22
views
How to implement method with generic return type in C#?
I have two method which are fairly close as logic and I was wondering can it be done with generic method instead?
First method:
public async Task<OrderDetailsModel> GetOrderAsync(string ...
0
votes
2
answers
159
views
What return this function in typescript?
When I hover on the keyword 'function' the description says:
"(local function)(this: any, next: (err?: mongoose.CallbackError | undefined) => void): Promise<void>"
So does It ...
2
votes
2
answers
114
views
Why does this error state my class does not implement this interface method?
I have a class that implements an interface and legacy from other class.
I don't know why my code is bad.
The error I get is:
CS0738 'SizeTypeService' does not implement interface member '...
1
vote
3
answers
75
views
What is the difference between void function and int *function for returning arrays
When dealing with arrays as they are passed by reference is there a difference between function return type like this 2 examples:
int *swap (int *arr, int size)
{
// code
return arr;
}
// OR
...
1
vote
1
answer
34
views
TypeScript either or return type is not detecting properties
type MyReturnType = Promise<boolean> | void
interface TestInterface {
testFunction(): MyReturnType;
}
class TestClass implements TestInterface {
testFunction() {
}
}
const ...
1
vote
2
answers
100
views
Return an array without getting a Dangling pointer as result in C++
I want to return an array from a function in C++. I made this simple code to try to achieve it.
#include <iostream>
#include <vector>
std::vector<int> *getx()
{
std::vector<...
0
votes
2
answers
66
views
How to declare static variables as possible return types in TypeScript
I'm trying to declare a return type from a simple getter in TypeScript. That return type should conform to one of two static variables, associated with the class that implements them.
Take this code:
...
2
votes
2
answers
85
views
How to determine the return type of a function in template
I am trying to write a class similar to std::function, just to learn how it works but I am having problem determining the return type of the function.
I found this from one of the answers here on ...
0
votes
4
answers
128
views
Converting Treeset (object []) into an int[] array?
I am making a method to sort using Hashset/Treeset, however I am stopped when it comes to taking my Treeset and trying to return it back from the method. I know I could change the return type to ...
1
vote
0
answers
10
views
what type of an array for the p[f].firstname, p[f].lastname, etc.and how what does it means return "no statues"? I still have two another questions
Hi I have been doing a project for tic tac toe with some references and examples but there are some things that I cannot understand in this one coding I found in chegg. Our lecturer gave us a project ...
0
votes
2
answers
82
views
how to create a c++ recursive function to return a node custom object?
how are you?
I created a C++ recursive function in order to iterate over a binary tree and print out all the NODEs where the property COMPLETED = TRUE;
It´s working pretty fine because the type of the ...
2
votes
1
answer
42
views
How to represent two different types of data being returned by a class method in a UML diagram?
I have the following method:
def getInvoiceById(self, id):
for invoice in self.invoices:
if invoice.id == id:
return invoice
return False
inside a ...
1
vote
1
answer
70
views
What happens when opeator= returns void rather than T&?
In operator overloading, the assignment operator is normally defined as follows:
T& T::operator =(const T2& b);
which returns T& as result. But I want to know what happens when we return ...
0
votes
2
answers
70
views
Python how to restrict output type as dictionary?
I find an example.
from typing import List
def twoSum(nums: List[int], target: int) -> List[int]:
pass
So I'm trying to restrict the input as an integer, and the output as a dictionary. survey ...
0
votes
1
answer
44
views
What is the difference between void function and empty return type functions in Dart lang? [duplicate]
What is the difference between these two functions in Dart?
void _someFunction() {
// some logic here
}
_someOtherFunction() {
// some other logic here
}
So basically my question is that is ...
-1
votes
3
answers
97
views
how to return a class type in a method in Java
I have implemented a particular method to search a book corresponding to a given ISBN number and return that book. But I have used the return type as void in that method (searchBook method ) because I ...
0
votes
3
answers
42
views
Can't go through the array object received from the service but I can see its content
When I try to access to the array it returns undefined.
It is as if what I receive were inside another element, because in the console the array is not accessed directly, but rather you have to open a ...
1
vote
1
answer
126
views
using __new__ to return object from different classes depending on input
I wanted to override __new__ function, for a specific class, in such a way that depending on the input passed, it returns an object from a class or from another.
I wrote the following code - which ...
2
votes
1
answer
47
views
Get as many nested Records in returnType as the arguments passed to the function
What I am trying to achieve is typing a deeply nested ReturnType of a function, based on the number of arguments provided in the "rest" argument. For example, if we have:
getFormattedDates(
...
1
vote
1
answer
59
views
Typescript ReturnType problem for generic class method
I'm using typescript: 4.3.5
I have an abstract class:
abstract class Parent {
public get<Type>(id: number): Observable<Type> {
...
}
}
and a child class:
class Child extends ...
-1
votes
1
answer
75
views
How to return a private array in a public get method in C++?
I am trying to make a public member get function that will return the private variable emp. But I am getting an error in my get function that says
"return value type does not match the function ...
0
votes
1
answer
76
views
why I can't return anonymous type as generic in C#, while I can do the same for method parameters?
Consider this code:
using System;
class EntryPoint{
static void Main(){
f(new{ Name = "amir", Age = 24 });
}
static void f <T> (T arg){}
}
This code compiles ...
-2
votes
1
answer
52
views
How do I return a class member that is an array in Java?
Trying to get the return function to return the full array, but not able to do it with a for loop or without. Is there any way to get this done?
public class Teams {
String Game;
String ...
1
vote
2
answers
31
views
create a to_vector function that can conditionally const cast to elements of input range based on output type
I would like to create a to_vector function that works with input vieweable_ranges. I can easily get this to work if input view and output vector have exactly the same type, but cannot get it to work ...
0
votes
1
answer
50
views
returntype depending on template argument type
So I'm trying to write an algorithmic derivator, to derivate/evaluate simple polynomials.
My Expression Logic is as follows: there are Constants and Variables, combined in to either a multiply or add ...