使用函数返回的值初始化 c++ 标头中的 const 值
Initializing const value in c++ header with value returned by function
有没有办法在 c++ 标头 "foo.hpp" 中定义 conastant foo"
const int foo;
并使用"bar.hpp"中定义的函数栏返回的值对其进行初始化
int bar();
?(无论是在foo.hpp中还是在foo.cpp中。
写入
extern const int foo;
在 foo.hpp 和
const int foo = bar();
在福.cpp。
当然有:
// foo.hpp
const int foo = bar();
正如你在这里看到的,它工作得很好。