【问题标题】:Replace preprocessor macro of string literal with concatenation用连接替换字符串文字的预处理器宏
【发布时间】:2022-06-14 00:05:12
【问题描述】:

我正在尝试用适当的 c++17 构造替换代码中尽可能多的宏使用。如何将以下宏替换为 constexpr 或其他内容?

#define FNAME "first"
#define LNAME "last"
#define NAME FNAME LNAME
const char hello[] = "hello " NAME;

【问题讨论】:

  • 你可以在编译时连接字符串,但如果我是你,我会创建一个返回静态 const 字符串的小函数,它会在你第一次调用时生成。

标签: c++ c++17


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-21
  • 2017-09-18
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
  • 2015-10-04
  • 1970-01-01
相关资源
最近更新 更多