[問題] declaration of function in a function

看板C_and_CPP作者 (Up2u)時間9年前 (2016/04/24 18:33), 編輯推噓1(105)
留言6則, 4人參與, 最新討論串1/1
請問在一個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

04/24 19:23, , 1F
跟extern一樣,讓function知道有別的function可以呼叫
04/24 19:23, 1F

04/24 20:09, , 2F
謝謝
04/24 20:09, 2F

04/26 10:17, , 3F
這題看起來只是想考你那行是否等價於 Test t1; XD
04/26 10:17, 3F

04/26 23:29, , 4F
推樓上, 這是 C 留到 C++ 的一個非常容易令人搞錯的地方
04/26 23:29, 4F

04/26 23:30, , 5F
C++ 規定當這種東西看起來像宣告時它就是宣告
04/26 23:30, 5F

04/28 18:50, , 6F
謝謝各位大大XD
04/28 18:50, 6F
文章代碼(AID): #1N7A3pEG (C_and_CPP)