有没有办法在 C++ 头文件“foo.hpp”中定义常量 foo
const int foo;
并用“bar.hpp”中定义的函数 bar 返回的值初始化它
int bar();
? (在 foo.hpp 或 foo.cpp 中。)
最佳答案
写
extern const int foo;
在 foo.hpp 和
const int foo = bar();
在 foo.cpp 中。
关于c++ - 使用函数返回的值初始化 C++ header 中的 const 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19572386/