简体   繁体   English

不带参数的功能Vs带参数的功能

[英]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.

相关问题 调用C函数,该函数不带参数参数 - Calling C function which takes no parameters with parameters 为需要可变数量参数的函数编写替换(c编程) - writing a replacement for a function which takes a variable number of parameters (c programming) 哪个函数不需要类似于Linux中的system(const char)的常量参数 - which function takes no constant parameters similar to system(constant char) in linux 在C语言中接受ENUM参数的函数中的错误 - A bug in a function which takes an ENUM arguments In C 将pthread作为输入并暂停的函数 - Function which takes a pthread as input and suspends it 如何在用作tcp服务器的线程中使用带有函数参数的函数 - How to use a function which takes a function parameter, in a thread that is used as a tcp server 什么是定义函数的最佳方法,该函数在C中作为参数使用true或false - What is best approach to define function which takes true or false as parameter in C 创建一个函数指针,该函数指针将函数指针作为参数 - Create a function pointer which takes a function pointer as an argument 指向获取指针参数的函数的指针 - Pointer to a function that takes pointer parameters 如何在struct中正确定义一个函数指针,它将struct作为指针? - How to properly define a function pointer in struct, which takes struct as a pointer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM