void

Python void return type annotation

我怕爱的太早我们不能终老 提交于 2020-06-24 07:01:27
问题 In python 3.x, it is common to use return type annotation of a function, such as: def foo() -> str: return "bar" What is the correct annotation for the "void" type? I'm considering 3 options: def foo() -> None: not logical IMO, because None is not a type, def foo() -> type(None): using the best syntax I know for obtaining NoneType , def foo(): omit explicit return type information. Option 2. seems the most logical to me, but I've already seen some instances of 1. 回答1: This is straight from

The void(), the comma operator (operator,) and the impossible (?) overloading

感情迁移 提交于 2020-02-27 04:22:50
问题 Consider the following struct: struct S {}; In C++14, the definition below is valid: constexpr auto f() { return S{}, 'c'; } As well as the following one: constexpr auto f() { return S{}, void(); } Now, consider the following, working snippet that involves the first of the two definitions: #include<type_traits> struct S {}; constexpr int operator,(S, char) { return 42; } constexpr auto f() { return S{}, 'c'; } int main() { constexpr int i{f()}; static_assert(i == 42, "!"); static_assert(std:

The void(), the comma operator (operator,) and the impossible (?) overloading

落花浮王杯 提交于 2020-02-27 04:21:32
问题 Consider the following struct: struct S {}; In C++14, the definition below is valid: constexpr auto f() { return S{}, 'c'; } As well as the following one: constexpr auto f() { return S{}, void(); } Now, consider the following, working snippet that involves the first of the two definitions: #include<type_traits> struct S {}; constexpr int operator,(S, char) { return 42; } constexpr auto f() { return S{}, 'c'; } int main() { constexpr int i{f()}; static_assert(i == 42, "!"); static_assert(std:

Cannot implicitly convert type 'void' to 'int'?

天涯浪子 提交于 2020-02-15 05:55:04
问题 Oke so I am fairly new to programming and I don't get why I get this error. My method should store mails which it does in this method: public void StoreMail(PhishingMail PhishingMail) { using (var phishingMailStorage = new PhishFinderModel()) { phishingMailStorage.PhishingMail.Attach(PhishingMail); phishingMailStorage.SaveChanges(); } And then in my processPhishingMail method it calls the Store method. But then I get the error: Cannot implicitly convert type 'void' to 'int'. public void

Cannot implicitly convert type 'void' to 'int'?

怎甘沉沦 提交于 2020-02-15 05:54:07
问题 Oke so I am fairly new to programming and I don't get why I get this error. My method should store mails which it does in this method: public void StoreMail(PhishingMail PhishingMail) { using (var phishingMailStorage = new PhishFinderModel()) { phishingMailStorage.PhishingMail.Attach(PhishingMail); phishingMailStorage.SaveChanges(); } And then in my processPhishingMail method it calls the Store method. But then I get the error: Cannot implicitly convert type 'void' to 'int'. public void

Typecasting void double pointer to void, why? [duplicate]

浪尽此生 提交于 2020-01-30 12:31:11
问题 This question already has answers here : What does casting to `void` really do? (4 answers) Closed 3 months ago . The code I'm working on has a function which has a double pointer of type void, in the function pointer the double pointer is typecasted to void, and the pointer is not used anywhere else. I cant find any where why this is done. someone please shed some light. static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, int num_prompts,

Typecasting void double pointer to void, why? [duplicate]

纵然是瞬间 提交于 2020-01-30 12:28:27
问题 This question already has answers here : What does casting to `void` really do? (4 answers) Closed 3 months ago . The code I'm working on has a function which has a double pointer of type void, in the function pointer the double pointer is typecasted to void, and the pointer is not used anywhere else. I cant find any where why this is done. someone please shed some light. static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, int num_prompts,

Returning a void?

不羁的心 提交于 2020-01-09 03:43:05
问题 I do not understand why this code compiles without error: #include <iostream> template <class T> struct Test { static constexpr T f() {return T();} }; int main() { Test<void> test; test.f(); // Why not an error? return 0; } Is it ok according to the standard, or is it a compiler tolerance? 回答1: This looks valid by the draft C++11 standard, if we look at section 5.2.3 Explicit type conversion (functional notation) paragraph 2 says ( emphasis mine ): The expression T() , where T is a simple

Void methods can't return the value of a void method?

自作多情 提交于 2020-01-05 08:25:12
问题 I don't mind if I don't understand, but I want to know why this happens: void something(String a) { return hi(); } void hi() { return; } The odd thing here, is that hi() also has a return type of void . I get the syntax error in my IDE: Void methods cannot return a value Furthermore, the code doesn't compile: Exception in thread "main" java.lang.Error: Unresolved compilation problem: Void methods cannot return a value at Resources.setSystemProperties(Resources.java:33) at Resources.main

Unable to understand placeholder _ behavior in scala function application

╄→尐↘猪︶ㄣ 提交于 2020-01-05 03:06:29
问题 Welcome to Scala version 2.10.2 Type in expressions to have them evaluated. Type :help for more information. scala> val fn = (x:Int) => x+1 fn: Int => Int = <function1> scala> val fn1 = fn _ fn1: () => Int => Int = <function0> scala> val fn2 = fn1 _ fn2: () => () => Int => Int = <function0> I don't understand why the placeholder(without a suggested type) application to a function is creating a new curried function with prefixed additional void argument. I was expecting a compiler error or at