作者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://www.ptt.cc/bbs/C_and_CPP/M.1461494003.A.390.html
→ Caesar08: 跟extern一樣,讓function知道有別的function可以呼叫 04/24 19:23
→ bjk: 謝謝 04/24 20:09
→ tinlans: 這題看起來只是想考你那行是否等價於 Test t1; XD 04/26 10:17
推 LPH66: 推樓上, 這是 C 留到 C++ 的一個非常容易令人搞錯的地方 04/26 23:29
→ LPH66: C++ 規定當這種東西看起來像宣告時它就是宣告 04/26 23:30
→ bjk: 謝謝各位大大XD 04/28 18:50