void

Void and return in Java - when to use

怎甘沉沦 提交于 2019-11-28 02:22:48
问题 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 +=

How to declare a void pointer in C#

狂风中的少年 提交于 2019-11-28 01:59:05
How can we declare a void pointer in C#? void* identifier; as described here But it needs to be in unsafe as: unsafe { void* identifier; } And unsafe code has to have been allowed for the project. I'm assuming you mean in managed code, as your question is rather short to do anything but assume. I think you're either looking for IntPtr or simply any object reference (which is the base type, and the basic equivalent of a null pointer - a reference to "something"). Unless you mean null pointer, in which case you're looking for IntPtr.Zero . there's something here: http://msdn.microsoft.com/en-us

How to call function from another form

痴心易碎 提交于 2019-11-28 01:43:39
问题 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

how does int main() and void main() work [duplicate]

拟墨画扇 提交于 2019-11-27 21:28:48
This question already has an answer here: What should main() return in C and C++? 17 answers I am a beginner in C language. Can anyone explain in detail using example how main(),int main(), void main(), main(void), void main(void), int main(void) work in C language? As in what is happeneing when we use void main() and what is happening when i use int main() in simple language and so on. I know but cant understand what is it doing: main() - function has no arguments int main() - function returns int value void main() - function returns nothing etc. when i write simple hello world using the int

What does the void() in decltype(void()) mean exactly?

匆匆过客 提交于 2019-11-27 21:11:09
This is a follow-up of this question, more precisely of the comments of this answer. What does the void() in decltype(void()) represent exactly? Does it represent a function type, an expression or whatever? Yakk - Adam Nevraumont Using a hyperlinked C++ grammar , the parsing of decltype(void()) is: decltype( expression ) decltype( assignment-expression ) decltype( conditional-expression ) ... lots of steps involving order of operations go here ... decltype( postfix-expression ) decltype( simple-type-specifier ( expression-listopt ) ) decltype( void() ) So void() is a kind of expression here,

Void as return type

蓝咒 提交于 2019-11-27 21:01:09
I was testing return types with PHP 7. I've created a simple script to test return types of PHP 7: <?php Class Obj { public function __construct(){ } public function test(): string { //a string needs to be returned return "ok"; } } function foo(): Obj { //instance of Obj needs to be returned return new Obj(); } $o = foo(); echo $o->test(); // output: ok Now in other programming languages when you specify a return type void it means you cannot return anything or you will get an error. So I wrote this script: <?php function foo(): void { } foo(); Now in above script the expected output is

What is the need of Void class in Java [duplicate]

风格不统一 提交于 2019-11-27 19:34:56
This question already has an answer here: Uses for the Java Void Reference Type? 11 answers I am not clear with the class java.lang.Void in Java. Can anybody elaborate in this with an example. It also contains Void.TYPE , useful for testing return type with reflection: public void foo() {} ... if (getClass().getMethod("foo").getReturnType() == Void.TYPE) ... Say you want to have a generic that returns void for something: abstract class Foo<T> { abstract T bar(); } class Bar extends Foo<Void> { Void bar() { return (null); } } Actually there is a pragmatic case where void.class is really useful.

What does `((void (*)())0x1000)();` mean? [duplicate]

别等时光非礼了梦想. 提交于 2019-11-27 19:17:02
This question already has an answer here: What does C expression ((void(*)(void))0)(); mean? 5 answers Here is a code that purpose is to set the program counter to jump to address 0x1000 . I know what it does but I don't understand how. It is related to my lack of C language knowledge. May be you can enlighten me. Here is the statement/function (I even don't know what it is :)) ((void (*)())0x1000)(); I thing it is pointer to a functions that returns void and accepts no argument. Please correct me if I am wrong. C declarations are decoded from inside out using a simple rule: start from the

EasyMock: Void Methods

谁说胖子不能爱 提交于 2019-11-27 17:14:27
I have a method that returns void in a class that is a dependency of the class I want to test. This class is huge and I'm only using this single method from it. I need to replace the implementation of this method for the test as I want it to do something different and I need to be able to access the parameters this method receives. I cannot find a way of doing this in EasyMock . I think I know how to do it with Mockito by using doAnswer but I don't want to add another library unless absolutely necessary. matt b If I understand what you want to do correctly, you should be able to use andAnswer(

Need for prefixing a function with (void)

喜你入骨 提交于 2019-11-27 15:42:12
I recently came across a rather unusual coding convention wherein the call for a function returning "void" is prefixed with (void). e.g. (void) MyFunction(); Is it any different from the function call like: MyFunction(); Has it got any advantage or is it yet another needless but there coding convention of some sort? Some functions like printf() return a value that is almost never used in real code (in the case of printf, the number of characters printed). However, some tools, like lint , expect that if a function returns a value it must be used, and will complain unless you write something