Questions tagged [return-type]
This tag is for questions dealing with the type of the variable or value returned by a function.
1,524
questions
0
votes
0
answers
7
views
Why does this Kotlin function definition have an extra empty set of parentheses before the return type?
I'm going through one of Google's Kotlin codelabs. I'm in Kotlin fundamentals under Android basics with Compose > Building app UI > Kotlin fundamentals, and I'm on section 5, "Use function ...
0
votes
1
answer
72
views
Trying to deep merge on type level
I have a JavaScript mergeDeep function that recursively merges objects and arrays. It works as expected in terms of functionality, but I want to improve it by ensuring that the return type of the ...
0
votes
0
answers
39
views
Return type of Function with Parameters
def add(num1:int,num2:int ) -> str:
num3 = num1+num2
return num3
num1 , num2 = 5,6
ans = add(num1,num2)
print(type(ans))
print(f"Addition of {num1} and {num2} is {ans}")
I was ...
0
votes
1
answer
44
views
RETURN cannot have a parameter in function returning set while returning from function
I have following code but this is throwing error:
RETURN cannot have a parameter in function returning set
Any idea on how I can fix it and why I am getting this error?
DROP FUNCTION IF EXISTS ...
-1
votes
3
answers
113
views
Is it OK to return a struct in a C function, or is it better to return a pointer to a struct created with malloc() [closed]
Both options are legal, but which one is better or "cleaner" :
Suppose we have this structure:
typedef struct MyStruct {
int val;
} MyStruct;
1st option; returning directly a struct:
...
0
votes
1
answer
23
views
How can I return different values in a FormComponent method?
I have this method that is going to create 2 textfields and a combobox.
But I have a problem returning the different values because it gives me an error that "Type mismatch: cannot convert from ...
-2
votes
2
answers
45
views
Text Box functions have wrong return type in Windows forms app [closed]
I've recently started learning .NET development. I was trying to make a basic SQL server connect form and I keep running into a wrong return type error for the Text Box functions that accept the ...
0
votes
0
answers
29
views
What is the proper way to override a method's return type in TypeScript?
In the Point2D class below, I got the compiler to stop complaining about the following error:
Property 'clone' in type 'Vector2D' is not assignable to the same property in base type 'Point2D'.
By ...
2
votes
1
answer
80
views
Why is there an error when the return type is std::string in C++?
I have an enum class and a map which matches enum class values to strings.
For example,
enum class FRUIT {
APPLE,
ORANGE,
MELON
};
std::map<FRUIT, std::string> m {
{FRUIT::APPLE,...
0
votes
0
answers
32
views
c++.net Winform function cannot be destinguished even though it has a unique name
I am writing a simulation with a winform user interface in C++.
To pass information to the user interface, I intend to use a structure that is passed as a function.
I have multiple files that are all ...
1
vote
1
answer
28
views
Typescript: getting ReturnType of a function called with certains Parameter types
Functionally, I want to provide 2 interface to access my database:
dao may be used by admins or regular users, so we need to provide isAdmin:boolean as first param of each function (eg: updateUser(...
2
votes
2
answers
98
views
What is the difference of using `typename` in the following?
What is the difference between using "typename" before the return type of a function and without using it at the declaration of a function like the following below?
And what is different if ...
0
votes
2
answers
30
views
Data type of Function with void return type and taking no input parameters
I am unable to figure what would be the return type of these functions fooBar() and barFoo()
in Java and getting the following errors.
import java.util.function.Function;
class FooBar {
private ...
0
votes
1
answer
27
views
PHP - Spoofing return-type covariance for code prediction
Consider:
abstract class BaseModel {
protected static string $dataObjectClass;
public function toDataObject(): ?IDataObject
{
return static::$dataObjectClass::from($this);
}
}
...
0
votes
0
answers
28
views
(Used PyCharm, Python, OpenCV, Mediapipe) When using Mediapipe what does process() function return?
Here is the code.
import cv2
import mediapipe as mp
webcam=cv2.VideoCapture(0)
mp_face=mp.solutions.face_mesh
mp_drawing=mp.solutions.drawing_utils
with mp_face.FaceMesh(min_detection_confidence=0.5,...
0
votes
0
answers
9
views
Return an objet or id from post request
Does a post request have to return a DTO like that:
return CreatedAtAction(nameof(GetUser), new { id = _user.Id }, _user);
or only the id
return CreatedAtAction(nameof(GetUser), new { id = _user.Id },...
1
vote
1
answer
87
views
How does return work within a Monad context within Haskell
Why does the following, given that the RegModule instance defines its return as: return a = RegModule (\_s _i d -> return (a, 0, d)), not return [((c, i+1, d), Int, d)], and why does the second ...
4
votes
1
answer
162
views
Marking the return value of a property in a method signature as readonly in C#
Visual studio is recommending I add the readonly keyword to the return signature of some methods and properties (IDE 0251). IDE 0251 has no title or description, which looks like it has been reported ...
1
vote
2
answers
100
views
How to get return type of class method?
I tried to use std::result_of, but could not manage it.
#include <type_traits>
class Foo
{
public:
int foo();
};
int main()
{
using return_type = std::result_of_t<Foo::foo()>; //...
0
votes
0
answers
14
views
Cannot Convert value of type "CLLocationCoordinates2D" to closure result type 'Void' [duplicate]
In this swift code, I am trying to make the function convert an address to a string, and after it does so successfully, it should return the coordinate as a CLLocationCoordinate2D
The error, Cannot ...
1
vote
1
answer
84
views
Collecting return types from vararg Callable for use elsewhere in signature?
I have the following function signature:
Y = Annotated[TypeVar("Y"), "That which might be yielded"]
R = Annotated[TypeVar("R"), "That which might be returned"]
...
1
vote
1
answer
38
views
Typescript return type of intersected functions is mismatched with the inferred type
As I was trying to extract the return type of a request that is intersected, I came across the this mismatch of the return type and the inferred type. Here is the shortened url https://tsplay.dev/...
1
vote
1
answer
54
views
Kotlin return type inference based on multiple parameter types
As a followup to Kotlin return type inference based on parameter type and incorporating its answer, here is my next question. Consider the following code:
enum class Usage {
REQUIRED,
OPTIONAL,...
1
vote
3
answers
92
views
Kotlin return type inference based on parameter type
I have a function:
object CliUtils {
var skipOptionalArgs = false
fun readOptional(variableName: String, defaultValue: String? = null): String? {
if (skipOptionalArgs) return ...
1
vote
1
answer
46
views
Incompatible pointer types returning swift class from Obj-C function
I have a swift protocol Fruit, a swift class Pear, and a method in an Objc-c file returning a pointer to Pear.
protocol Fruit: NSObjectProtocol {
}
@objcMembers
class Pear: NSObject, Fruit {
init()
...
1
vote
1
answer
52
views
Why does Kotlin resolve return type inconsistently?
Given the following code:
inline fun <reified T> T?.or(other: () -> T): T {
return this ?: other()
}
fun getValue(): String {
while (true) {
return "Value 1"
}
}...
1
vote
3
answers
96
views
Can I use the return type "object" in Java? Dangers?
During a project the need for a queue supporting two different datatypes arose. I solved this by creating a java.util linked list using java.util queue interface. I do however need to use the return ...
0
votes
3
answers
54
views
Confusion on inferred return type
I was working with Typescript and got confused with how the compiler infers the return types differently for these two functions.
//this is of type () => boolean | ""
const isFormValid = (...
2
votes
1
answer
78
views
differentiate and nest function with template return type
What I want:
I have an issue with using 'nested'(?) templates as return type for my functions. The function declaration should look something like this:
// ### Generate.hpp
// return the template type
...
0
votes
1
answer
42
views
C# methodology advices in DLL dev, and custom result classes
I would need some advice on development methodology in a C# DLL with a GUI, especially on the return objects of the methods which must return both processing results and possible exceptions or errors, ...
-1
votes
1
answer
67
views
Difference between 'void' and ' <T> void' in java method [closed]
public static <T> void myMethod(int a, Consumer<T> consumer){// Some code}
public static void myMethod(int a, Consumer<T> consumer){// Some code}
Difference between 'void' and '<...
1
vote
0
answers
37
views
Return Type of a Function?
I am trying to write an AI in unity for a simple 2D game I have made, I am trying to use the code from a simple genetic algorithm tutorial on unity but I don't what type of return unity wants me to ...
0
votes
0
answers
17
views
Dummy return value for Generic Method [duplicate]
I'm writing a few empty generic methods that I plan on coming back to finish later. However, I still want the program to compile. How do I return an empty generic method?
For example:
public AnyType ...
0
votes
0
answers
33
views
lambda return type restriction for C++11 [duplicate]
So i am working on a C++11 project and i have class structure something like this
header file
class AgentClassInterface {
public:
virtual void doSomething() = 0;
};
class AgentClass : public ...
0
votes
0
answers
54
views
Generic type with suggested functions in any property interface in Typescript
This is a followup to this question and this question.
// return type
interface DataA {
value: number;
}
// return type
interface DataB {
text: string;
}
// return type
interface DataC {
has: ...
-3
votes
2
answers
51
views
Void function with an Error of non-void function does not return a value [closed]
Could anyone help me understand why this function produces an error of:
error: non-void function does not return a value
[-Werror,-Wreturn-type]
}
^
1 error generated.
void *ft_clearpath(char **arr)
{...
0
votes
1
answer
52
views
Expect functions and suggest function names in generic class
Hi everyone. 😊
This is a followup to this question.
interface Works {
call(): void;
}
interface DoesntWork {
value: number;
}
interface ShouldWork {
value: number;
call(): void;
}
class ...
0
votes
0
answers
12
views
Return something from Closure
def create_counter():
count = 0
def counter_inner():
nonlocal count
count += 1
print(f'Closure called {count} times')
return counter_inner
c1 = create_counter()
c2 ...
3
votes
0
answers
112
views
Specifying of full namespace in function return type
I have the following code.
Header file myclass.h:
namespace A::B
{
template<typename Type, unsigned int Count>
class MyClass
{
public:
MyClass() = delete;
...
1
vote
1
answer
138
views
Depending Generic ResultType in Typescript
😊 Hi everyone!
interface Data {
date: Date;
message?: string;
}
interface DataB {
dateB: Date;
messageB?: string;
}
class DataResolver {
public submit(): Data {
return { date: new ...
0
votes
2
answers
86
views
How to deduce return type of each function (on derived class) stored in a container
I would like to get return type of each function stored in a container. I have tried std::any and std::variant but i couldn't figure this out. Details below:
#include <random>
#include <...
0
votes
1
answer
43
views
How can I make a java method return an object found in a list of objects? [duplicate]
I have this code:
public Task getTask(String taskID) {
for (Task item : tasks) {
if (item.getTaskID() == taskID) {
return item;
}
}
...
0
votes
2
answers
70
views
Python - possible problem returning a value in a function which can rerun itself
# Python code to check input for "" and diving by zero error
def getNumber():
x = input("Enter a number to divide 100 by: ") # string!!
if x == "&...
2
votes
1
answer
57
views
Purpose of return expression in c
#include<stdio.h>
long int multiplyNumbers(int n);
int main()
{
int n;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factorial of ...
-1
votes
2
answers
62
views
Need to only return what's in the if-statement, but get an error with only one return statement
For my program, I'm trying to just return the value of index, which is equal to i. Except Java won't let me return just that if-statement without an error message. I added a return index statement at ...
-1
votes
1
answer
51
views
What can I use instead of 'None' so it'll be iterable? [closed]
Is there something I can return instead of 'None' so that it's still iterable but empty?
Sometimes I want to return two values but sometimes I only want to return one.
for distance in range(1, 8):
...
1
vote
0
answers
31
views
Complex unions as return type annotations in Python?
I'm writing a basic python function that takes user input, checks if it's valid, and returns True if the input is valid and False accompanied by an error message of type str if not. Here's what my ...
1
vote
2
answers
251
views
Template function deducing return type
I am trying to create a simple template function which takes a callable object and a couple of int values as parameters to that callable, and returns the result of invoking the callable with those ...
2
votes
1
answer
92
views
How to return a generic struct in Rust
Beginner in Rust, I'm wondering how to return generic data in a function.
pub fn tryparse() -> (CLIAction, ArgSingle) {
let args = CLI::from_args();
match args.cmd {
SubCommand::Add(...
0
votes
0
answers
84
views
TS can't infer return type of simple function
I feel like I've done this a thousands times and it should work. Why doesn't it?
I am sending string so TS should know a string will come back out, right?
export function sayHi(text: string | null) {
...