(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)

谢谢

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐