[问题] declaration of function in a function

楼主: bjk (Up2u)   2016-04-24 18:33:20
请问在一个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.
作者: Caesar08 (Caesar)   2016-04-24 19:23:00
跟extern一样,让function知道有别的function可以呼叫
楼主: bjk (Up2u)   2016-04-24 20:09:00
谢谢
作者: tinlans ( )   2016-04-26 10:17:00
这题看起来只是想考你那行是否等价于 Test t1; XD
作者: LPH66 (-6.2598534e+18f)   2016-04-26 23:29:00
推楼上, 这是 C 留到 C++ 的一个非常容易令人搞错的地方C++ 规定当这种东西看起来像宣告时它就是宣告
楼主: bjk (Up2u)   2016-04-28 18:50:00
谢谢各位大大XD

Links booklink

Contact Us: admin [ a t ] ucptt.com