6.12. Functions with Empty Parameter Lists

In C++, an empty parameter list is specified by writing either void or nothing at all in parentheses. The prototype

void print();

specifies that function print does not take arguments and does not return a value. Figure 6.17 shows both ways to declare and use functions with empty parameter lists.

 1   // Fig. 6.17: fig06_17.cpp 2   // Functions that take no arguments. 3   #include <iostream> 4   using namespace std; 5  6   void function1(); // function that takes no arguments       7   void function2( void ); // function that takes no arguments  8  9   int main()10   {11      function1(); // call function1 with no arguments 12      function2(); // call function2 with ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.