[英]When defining a prototype of an overloaded C++ function template, is it legal to use its name to refer to previous definitions?
[英]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)
調用中給error額外的參數。
該代碼在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;
}
看來您的編譯器不是那么聰明。 考慮使用另一個編譯器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.