2013-10-24 56 views
0

返回值報頭是否有任何方式在C++頭「foo.hpp」初始化在C const的值++與由函數

const int foo; 

定義conastant foo和與由所述功能欄中返回的值初始化爲「欄.hpp「

int bar(); 

? (無論是在foo.hpp或Foo.cpp中)

+0

'#include「bar.hpp」'然後'const int foo = bar();'? – jrok

+0

你的意思是'const int foo = bar();'?或者我錯過了什麼? –

+0

爲什麼不是'static const'成員?可以使用全局/名稱空間變量,但我更喜歡'static const'cus,您不必擔心extern。 – IdeaHat

回答

1

extern const int foo; 

foo.hpp

const int foo = bar(); 

Foo.cpp中

+0

謝謝,工作! – user2643716

1

當然有:

// foo.hpp 
const int foo = bar(); 

,你可以see here它工作得很好。