c++中重载函数的原型
prototype for overloaded function in c++
为什么我不能像对待其他函数一样,在main()
中为重载函数提供原型??例如,我写了以下代码
#include<iostream.h>
#include<conio.h>
void main()
{
void a(float);
void a(float,float);
a(2.4);
a(5.6,7.4);
getch();
}
void a(float x)
{
cout<<x;
}
void a(float y,float z)
{
cout<<y<<z;
}
在运行此代码时,turbo c++编译器给出了一个错误,我观察到它忽略了函数a
的第二个声明,即void a(float,float);
,因此在调用a(float)
时给了错误额外的参数。
此代码在Wandbox上运行良好。
#include<iostream>
//#include<conio.h>
using std::cout;
int main()
{
void a(float);
void a(float,float);
a(2.4);
a(5.6,7.4);
//getch();
}
void a(float x)
{
cout<<x;
}
void a(float y,float z)
{
cout<<y<<z;
}
你的编译器似乎不那么聪明。请考虑使用另一个编译器。
相关文章:
- 函数向量_指针有不同的原型,我可以构建一个吗
- 具有enable_if外部类原型的模板类构造函数定义
- 函数如何通知用户它基于函数原型抛出异常?
- 在函数中拥有函数原型的目的是什么?
- 什么..(省略号)作为函数原型中唯一的函数参数,C++?
- 是否可以使用 libclang python 解析 cpp 文件中没有标头的函数原型
- 有没有办法在C++编译时更改函数原型?
- 省略函数原型中的返回类型
- 如何使用 "using" 关键字定义函数原型/签名
- 未定义原型函数?
- SFINAE :删除具有相同原型的函数
- 函数原型未初始化的局部变量
- 如何创建函数原型命名空间
- 如何使用这个原型函数char*encrypt(char*pEncryptedText,const char*pText)
- C++:警告:C4930:未调用原型函数(是否为变量定义?)
- 编写原型函数(c++)
- 我有在c++编程中创建和执行原型函数的麻烦
- 需要为原型函数创建一个单独的cpp文件
- 用Emacs从.h中自动插入原型函数
- 如何修复错误 C4930:"AMyStaticMeshActor a(void)":未调用原型函数(是否打算使用变量定义?