0

In this code I am overloading the function. But can someone tell me why there is void in the argument brackets of main function. I tried to remove void from the brackets of main function code still works. Any idea ?

#include <iostream.h> 

class printData 

{ 

public: 

void print(int i) 

{

cout << "Printing int: " << i << endl; 

} 

void print(double f) 

{ 

cout << "Printing float: " << f << endl; 

} 

void print(char* c) 

{ 

cout << "Printing character: " << c << endl; 

} 

}; 

int main(Void) 

{ 

printData pd; 

pd.print(5);        // Call print to print integer

pd.print(500.263);      // Call print to print float 

pd.print("Hello C++");  // Call print to print character 

return 0; 

}
AZEEM ZAIDI
  • 3
  • 1
  • 3

1 Answers1

0

(void) is the list of parameters that main is expecting from its caller. In most cases, its caller is the operating system (or, strictly speaking, the startup code that calls the main function in your program). In C, a void parameter list explicitly states that the function does not expect to receive any parameters from its caller. In C++, a parameter list (void) has the same meaning as an empty parameter list (). Find More Here

Bacon San
  • 1
  • 1