我知道你可以只是这样简单地声明一个没有任何参数的函数:
void test()
{
cout << "Hello world!!" << endl;
}
但我也见过
void test(void)
{
cout << "Hello world!!" << endl;
}
并且
void test(void*)
{
cout << "Hello world!!" << endl;
}
我的问题是:在这里使用void
和void*
有什么区别?
test()
和test(void)
是等效的,但在C语言中不是。除非需要C兼容性,否则应该优先选择前一种形式。函数test(void*)
与其他两个函数不同;它带有一个未命名的void*
类型参数。 - Brian61354270void
表示“什么也没有”,而void*
表示“某个东西的位置”。什么都没有和一个位置之间有很大的区别。 - molbdnilo