內聯函數能夠提高程序性能這是大家都知道的。但內聯函數應該怎樣申明和定義呢?今天我就遇到一個"unresolved external" 錯誤。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.
內聯函數體必須定義在頭文件中,除非你的程序只有單一cpp文件。如果你在一個cpp文件中定義內聯函數體,而要從其他cpp文件訪問該內聯函數,你就會在link時遇到
"unresolved external" 錯誤。原文鏈接看
這里。