(1)
(2) 使用示例 ,变量 :
#include <iostream>int main()
{[[maybe_unused]] int x = 10; // x 被声明但未使用,但使用 [[maybe_unused]] 避免警告std::cout << "Hello, World!" << std::endl;return 0;
}
(3)函数参数:
#include <iostream>void printMessage(const std::string& message, [[maybe_unused]] int priority)
{std::cout << message << std::endl;// priority 参数未使用,但使用 [[maybe_unused]] 避免警告
}int main() {printMessage("Hello, World!", 1);return 0;
}
(4)函数 :
#include <iostream>[[maybe_unused]] void unusedFunction() {std::cout << "This function is not used, but we want to keep it for future use." << std::endl;
}int main() {std::cout << "Hello, World!" << std::endl;return 0;
}
(5)
谢谢