作者bjk (Up2u)
看板C_and_CPP
标题[问题] declaration of function in a function
时间Sun Apr 24 18:33:20 2016
请问在一个function里面的declaration of function
是甚麽作用呢
谢谢
http://www.geeksforgeeks.org/output-of-c-program-set-5/
Question 3
#include<iostream>
using namespace std;
class Test
{
public:
Test();
};
Test::Test() {
cout<<"Constructor Called \n";
}
int main()
{
cout<<"Start \n";
Test t1();
cout<<"End \n";
return 0;
}
Run on IDE
Output:
Start
End
Note that the line “Test t1();” is not a constructor call. Compiler
considers this line as declaration of function t1 that doesn’t recieve any
parameter and returns object of type Test.
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.160.169.150
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1461494003.A.390.html
1F:→ Caesar08: 跟extern一样,让function知道有别的function可以呼叫 04/24 19:23
2F:→ bjk: 谢谢 04/24 20:09
3F:→ tinlans: 这题看起来只是想考你那行是否等价於 Test t1; XD 04/26 10:17
4F:推 LPH66: 推楼上, 这是 C 留到 C++ 的一个非常容易令人搞错的地方 04/26 23:29
5F:→ LPH66: C++ 规定当这种东西看起来像宣告时它就是宣告 04/26 23:30
6F:→ bjk: 谢谢各位大大XD 04/28 18:50