void

Why do I need to use the unit type in F# if it supports the void type?

◇◆丶佛笑我妖孽 提交于 2019-11-29 09:27:55
I read this MSDN article: Unit Type (F#) ...The unit type is a type that indicates the absence of a specific value; the unit type has only a single value, which acts as a placeholder when no other value exists or is needed ... The unit type resembles the void type in languages such as C# and C++... So... Alright, I understand, that the unit type is such a type, which has only a single value () . But I have some questions: Why is it needed? When is it needed? I don't understand why not to use the void type in F#, like C# and C++ use. If I look at the following table: Primitive Types (F#) Type

How much existing C++ code would break if void was actually defined as `struct void {};`

北战南征 提交于 2019-11-29 09:09:04
void is a bizarre wart in the C++ type system. It's an incomplete type that cannot be completed, and it has all sort of magic rules about the restricted ways it can be employed: A type cv void is an incomplete type that cannot be completed; such a type has an empty set of values. It is used as the return type for functions that do not return a value. Any expression can be explicitly converted to type cv void ([expr.cast]). An expression of type cv void shall be used only as an expression statement, as an operand of a comma expression, as a second or third operand of ?: ([expr.cond]), as the

Void and return in Java - when to use

一世执手 提交于 2019-11-29 09:01:43
I have some "confusion" about void and return. In general, I understand void is used in methods without returning anything, and return is used in methods when I want to return something to the calling code. But in the following code, I can use both, and my question is, which one to use? And how to determine? Is it about performance? Normally, I have the same results in both cases. public class Calc { private double number; Calc (double n) { number = n; } public void add(double n) { number += n; } public double add1(double n) { return number = number + n; } } Thank you! This method : public

How to call function from another form

亡梦爱人 提交于 2019-11-29 07:58:16
In my project I have a Settings form and a Main form. I'm trying to call the Main form's MasterReset function from the Setting form, but nothing happens. The Master form's Masterreset function looks like this. public void MasterReset() { DialogResult dialogResult = MessageBox.Show("Are you sure you want to perform master reset? All settings will be set to default.", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string phonebook_path = path + "\\Phonebook\

How can I return a default value for an attribute? [duplicate]

和自甴很熟 提交于 2019-11-29 04:56:41
问题 This question already has an answer here: A get() like method for checking for Python attributes 3 answers I have an object myobject , which might return None . If it returns None , it won't return an attribute id : a = myobject.id So when myobject is None , the stament above results in a AttributeError : AttributeError: 'NoneType' object has no attribute 'id' If myobject is None, then I want a to be equal to None . How do I avoid this exception in one line statement, such as: a = default

Object[] cannot be cast to Void[] in AsyncTask

余生颓废 提交于 2019-11-29 01:40:24
问题 I'm getting this error inside an extended asynctask, but i'm really sure that Object[] IS a Void[]. This is my custom AsyncTask: public abstract class RepeatableAsyncTask<A, B, C> extends AsyncTask<A, B, C> { private static final String TAG = "RepeatableAsyncTask"; public static final int DEFAULT_MAX_RETRY = 5; private int mMaxRetries = DEFAULT_MAX_RETRY; private Exception mException = null; /** * Default constructor */ public RepeatableAsyncTask() { super(); } /** * Constructs an AsyncTask

Array of POINTERS to Multiple Types, C

最后都变了- 提交于 2019-11-29 01:10:41
问题 Is it possible to have an array of multiple types by using malloc ? EDIT: Currently I have: #include <stdio.h> #include <stdlib.h> #include <string.h> #define int(x) *((int *) x) int main() { void *a[10]; a[0] = malloc(sizeof(int)); int(a[0]) = 4; char *b = "yola."; a[1] = malloc(strlen(b)*sizeof(char)); a[1] = b; printf("%d\n", int(a[0])); printf("%s\n", a[1]); } But it's messy. Other ways? EDIT: Cleaned it up a bit. 回答1: You can't have an array of different types, exactly. But you can

What's the point of const void?

ε祈祈猫儿з 提交于 2019-11-29 00:50:05
Apparently, it is possible to declare a function returning const void : const void foo() { } g++ seems to consider the const important, because the following code does not compile: #include <type_traits> static_assert(std::is_same<void(), const void()>::value, "const matters"); So does const void have any practical significance? Not really. But to ignore cv -qualifications on void or to make them errors could create unnecessary complexity in terms of both compiler implementation and end-user code. Consider templates like template<typename T> const T ... There's no reason to make using void in

isn't non-type parameter pack that evaluates to “void…” illegal?

房东的猫 提交于 2019-11-28 23:40:41
gcc-4.8 accepts this code, but isn't it wrong since the non-type parameter pack is equivalent to void... which is illegal? template <typename T, typename std::enable_if<std::is_integral<T>::value>::type...> void test(T) {} I tried this with clang-3.5 as well which also accepts it. Is this a compiler bug, or am I misunderstanding something? Full test code below, which uses non-type empty parameter packs to simplify enable_if. This is almost the same as what's in Flaming Dangerzone's Remastered enable_if except after substitution the pack becomes void... . #include <type_traits> template <

Construction of a void Type?

做~自己de王妃 提交于 2019-11-28 21:17:18
I was given a piece of code that uses void() as an argument. The code doesn't compile... obviously? Can we instantiate anything of type void ? I believed the answer was no, with the exception of a void* . For example: Writing the function void askVoid(void param) {} errors: A parameter may not have void type Writing the function void askNaught() {} and calling it with askNaught(void())` errors: error C2660: takeNaught : function does not take 1 arguments Writing the templatized function template <typename T> void takeGeneric(T param) {} and calling it with takeGeneric(void()) errors: error