A Small Difference between C and C++

If you look at the preceding program, which implements a queue, you will see that three of the functions, specifically main(), init(), and qput(), take no parameters. In the program, they were declared like this:




As you should know, to tell a C compiler that a function take no parameters requires that void be included in that function's parameter list. In C, an empty parameter list simply says nothing about the parameters. However, by using void, you explicitly tell the compiler would have most commonly been declared like this:




However, in C++, the use of the word void in this situation is optional and, indeed, superfluous. That is, in C++, when no parameters are specified in the parameter list, it is implied that thb functim takes no parameters. Thus, in C+, these two declarations are equivalent:



Since the use of void is unnecessary when declaring functions that take no parameters, it will not be used in this context in this book.

TURBO C++ for Windows inside n out by Herbert Schildt

No comments:

Post a Comment