Is there a difference between foo(void) and foo() in C++ or C?

前端 未结 4 515
情话喂你
情话喂你 2020-11-22 16:00

Consider these two function definitions:

void foo() { }

void foo(void) { }

Is there any difference between these two? If not, why is the <

4条回答
  •  抹茶落季
    2020-11-22 16:41

    In C, you use a void in an empty function reference so that the compiler has a prototype, and that prototype has "no arguments". In C++, you don't have to tell the compiler that you have a prototype because you can't leave out the prototype.

提交回复
热议问题