使用函数返回的值初始化c ++头中的const值

时间:2013-10-24 17:15:36

标签: c++ header const

有没有办法在c ++ header中定义fastant foo" foo.hpp"

const int foo;

并使用" bar.hpp"中定义的功能栏返回的值对其进行初始化。

int bar();

? (在foo.hpp或foo.cpp中。)

2 个答案:

答案 0 :(得分:1)

当然有:

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

尽可能see here它的工作正常。

答案 1 :(得分:1)

extern const int foo;
foo.hpp

中的

const int foo = bar();
foo.cpp 中的