我正在使用一个名为 spdlog 的库进行日志记录。我想围绕该库构建我自己的记录器,以便我可以选择添加特定于我的应用程序的“额外”功能。
我能够让下面的代码正常工作:
#include <spdlog/spdlog.h>
int main()
{
spdlog::log(spdlog::level::level_enum::info, "this is an info message");
return 0;
}
如您所见,日志记录级别可通过位于 spdlog::level::level_enum
命名空间的枚举获得。
我可能会让这个变得过于复杂,但是如果我创建自己的 Logger 类,我是否必须期望使用我的记录器的类在其日志记录函数调用中键入整个枚举的命名空间?
最佳答案
but if I create my own Logger class will I have to expect classes using my logger to type out the entire enum's namespace in their logging function calls
您可以在此处使用using
。像这样的东西:
using info = spdlog::level::level_enum::info;
这样可以防止您每次需要使用它时都键入整个内容。您只需要使用 info
即可。
关于c++ - 如何公开库的枚举,以便我的代码不必键入整个命名空间来使用该枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59868040/