內(nèi)聯(lián)函數(shù)能夠提高程序性能這是大家都知道的。但內(nèi)聯(lián)函數(shù)應(yīng)該怎樣申明和定義呢?今天我就遇到一個(gè)"unresolved external" 錯(cuò)誤。google后找到答案。
t's imperative that the function's definition (the part between the {...}) be placed in a header file, unless the function is used only in a single .cpp file. In particular, if you put the inline function's definition into a .cpp file and you call it from some other .cpp file, you'll get an "unresolved external" error from the linker.
內(nèi)聯(lián)函數(shù)體必須定義在頭文件中,除非你的程序只有單一cpp文件。如果你在一個(gè)cpp文件中定義內(nèi)聯(lián)函數(shù)體,而要從其他cpp文件訪問該內(nèi)聯(lián)函數(shù),你就會(huì)在link時(shí)遇到
"unresolved external" 錯(cuò)誤。原文鏈接看
這里。