c++ - 使用函数返回的值初始化 C++ header 中的 const 值

标签 c++ header constants

有没有办法在 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/

相关文章:

C++ 正则表达式,未知转义序列 '\.' 警告

c++ - opencv::带有垃圾名称的多个不需要的窗口

c++ - boost编译标志iw是什么意思?

c++ - 两个具有相同大小的可变模板参数

javascript - 为什么常数字段不 protected ?

wpf - 如何在 WPF Expander Header 中对齐 TexBlocks

iphone - XCode 如何处理具有多个目标的#import header 语句?

objective-c - Xcode 无法发出预编译 header ?

c++ - const 成员函数需要说明

c++ - int const function(parameters)、int function(const parameters) 和 int function(parameters) const 有什么区别?