c++ - Maybe_unused 属性说明符可以只出现一次并且仍然有效吗?
问题描述
我喜欢这个[[maybe_unused]]
属性,并且在我需要编译仅调试功能实现时经常使用它。将成员函数参数指定为[[maybe_unused]]
.
鉴于:
//Foo.h
class Foo {
void DebugOnly(Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly(Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
在这两个地方指定它会有所不同吗?
//Foo.h
class Foo {
void DebugOnly([[maybe_unused]] Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly([[maybe_unused]] Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
还是我应该只在头文件或实现文件中声明它?
仅标头
//Foo.h
class Foo {
void DebugOnly([[maybe_unused]] Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly(Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
仅实现文件
//Foo.h
class Foo {
void DebugOnly(Bar& fly);
}
//Foo.cpp
void Foo::DebugOnly([[maybe_unused]] Bar& fly) {
#ifdef _DEBUG
fly.squish();
#endif
}
cppreference上的页面不区分函数参数,仅将它们归类为“变量”。
解决方案
推荐阅读
- python - difference between instance variables and global variables declared in __init__ function
- python - importlib.import_module(m) 可以执行 `from m import *` 吗?
- c# - AddPolicy 和 Requireclaim 在 .net core 6.0 中没有按我预期的方式工作
- amazon-web-services - 以编程方式将所有 AWS 内联策略转换为当前 IAM 角色的托管策略
- sql - 如何使用 Firebase Firestore 制作 MCD、MLD 和类图?
- javascript - 如何在 Firebase DB 中获取和覆盖字符串 - React Native
- python - Django:list_display 接受字段但不接受 list_filter
- node.js - 如何让 heroku 尊重模块支持?
- java - 如何在 apache localhost 路径上创建和下载 zip?
- angular - 如何创建一个 Angular 指令来禁用输入字段