[英]function which takes no parameters Vs function which takes parameter
I was educated from here that 我从这里受教育
void f();
void f(int a) {
printf("%d", a);
}
the parameter type list "wins". 参数类型列表“ wins”。 I did the following...
我做了以下...
int fun(void); //parameter type list
int fun(int a, double b)//parameter type list
{
printf("%d, %f", a, b);
return 0;
}
I was expecting that compiler will throw an error (since overloading is not possible in c), but it didn't 我原以为编译器会抛出一个错误(因为在c中不可能重载),但是没有
Can anyone help me in this regards? 有人可以在这方面帮助我吗?
Thanks. 谢谢。
Since you're using Visual Studio, the most likely reason for your situation is that your code is in a C++ file. 由于您使用的是Visual Studio,因此最可能的原因是您的代码在C ++文件中。 Note that VS distinguishes between C and C++ files based on the file extension.
请注意,VS根据文件扩展名区分C和C ++文件。 Changing your file to a
.c
file rather than a .cpp
file should do the trick. 将文件更改为
.c
文件而不是.cpp
文件应该可以解决问题。
(Note that when you Add New Item
to create a source file, you can create a C file simply by adding a new C++ file and then changing the name of the created file to be .c
, as in the image below.) (请注意,在
Add New Item
以创建源文件时,只需添加新的C ++文件,然后将创建的文件名更改为.c
即可创建C文件,如下图所示。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.