Questions tagged [void]

An incomplete type used as syntactic place-holder for the return type of a method/function when no value is returned.

Programming languages derived from C or Algol68, like C++, C#, Java, etc., may define the return type of methods/functions as void when the method/function does not return a value, but simply completes execution.

An example of its use in Java, compared to a non-void method, is:

int nonVoidMethod {
    // do something
    return 0; // return a value to the caller
}

void voidMethod {
    // do something
    return; // no value allowed to be returned from a void method
    // a "return" statement is not required
}

Although void is used as a type, it's an incomplete type:

  • In some languages, such as Java and Algol68, void is only a keyword used as a return type. It is not considered as a valid type in other language constructs.

  • Other languages, like C and C++, consistently define void as a type with an empty set of values. This allows its use for example in compound type constructs (void pointers). But no void objects can be instantiated.

1913 questions
0
votes
2 answers

cpp(15): error C2182: 'input' : illegal use of type 'void'

after making a fresh start on a new program i made for learning how arrays work in combinatio0n with void ive ran into the following problem. cpp(15): error C2182: 'input' : illegal use of type 'void' Does anyone know what causes this? I am new to…
user3383990
  • 1
  • 1
  • 2
0
votes
1 answer

Getting data sets from separate text file

I was wondering if anyone could help me out with my problem. So the program I am working on tries to calculate the flight distance of non stop flights compared to flights that stop in one city other than the desired destination. So far I have gotten…
0
votes
1 answer

Program that calculates flight distance

I am having trouble with a program that uses void functions. I have never used them before so I'm a bit lost. My program has a 3 sets of cities. It is supposed to get the three cities in one of the sets and figure out how long the flight is. My…
0
votes
1 answer

error: expected unqualified-id (C++)

I am trying to create a basic text-based adventure game in C++. Here is one of my classes. #include "goblinFight.h" #include #include #include using namespace std; goblinFight::int fightGoblin() { cout << "A goblin…
0
votes
2 answers

Java no response from thread or other classes

Just a heads up, this question extends from my previous one Java no response from other classes . The answers I got on there we're great, but I'm encountering new problems; so this is a completely different question. Like I said before, I'm making a…
Arc
  • 441
  • 1
  • 9
  • 26
0
votes
1 answer

Java no response from other classes

I have this GUI program where I'm trying to basically copy windows CMD. Since I have lots of features in this program, I decided to put parts of the code in different classes. But it doesn't respond. if(command.size()<2 && command.size()>0)…
Arc
  • 441
  • 1
  • 9
  • 26
0
votes
5 answers

Write a static void method - "cannot find symbol" compile error

This is my assignment: Write a static void method called greeting with three String parameters that formats and prints a title, first name, and last name in the following format and prints it out. blank line Dear title first name last name, blank…
user3288334
  • 9
  • 1
  • 5
0
votes
4 answers

Arithmetic operation with a void?

I know that the following, if possible, would be an absolutely bad practice, but I want to know if this is possible. The question is the following: is it possible in C++ (and in a way the compiler does not throw any warning), to perform a useless…
Vincent
  • 57,703
  • 61
  • 205
  • 388
0
votes
2 answers

Trouble using "void *" in a linked list

I have a generic linked list that looks like this: queue.hpp typedef struct queue_node { struct queue_node *next; struct queue_node *prev; void *data; int32_t index; } queue_node; typedef struct queue { struct queue_node…
culight
  • 1
  • 2
0
votes
2 answers

Why does my void pointer change values in my program?

I have a the following in a header file. struct SortedList { void * data; struct SortedList * next; struct SortedList * previous; int (*compareFunc)(void *, void *); void (*destructor)(void *); }; typedef struct…
0
votes
4 answers

Calling a variable from a void method

Hey this is a very simple question. Can I call a variable, in this case an array, from a void method? I have declared my arrays at the class level and initialized them in a void method. Not sure it I am doing this correctly but I am trying to call…
handroski
  • 81
  • 2
  • 3
  • 15
0
votes
1 answer

How to run everything in a method in one class?

So Here's my question... I have a java program for checkers, I want to initialize the checkers in a different class, as a method (I Think), and then create all of them. Here's my code: http://pastebin.com/ansERKjv So how do I call the method…
Jake Sylvestre
  • 936
  • 3
  • 14
  • 39
0
votes
1 answer

Calling a non-static method return type void

For my program I'm creating 2 people, names and ages from the command-line. Then my program will display a toString in a dialog box for each person. However, I'm trying to implement two methods that changes the name data field and the age data field…
Asia x3
  • 606
  • 2
  • 16
  • 37
0
votes
1 answer

Why add void before methods?

Why do you need to add the keyword void before certain methods. I know it means the method returns nothing (or at least that's what I think it means), but why should you add void even if you already know the method is supposed to return nothing?
Fderal
  • 457
  • 1
  • 6
  • 11
0
votes
3 answers

Pass an argument in static void function C#

I am trying to write a C# function to determine the maximum value in an array and to pass it by reference. It is my first time programming in C#, but it's really bugging me that I don't to seem to be able to assign it correctly in the main. using…
radu-matei
  • 3,469
  • 1
  • 29
  • 47