Skip to content

建议修改命名空间, 不要放在std #33

@abin-z

Description

@abin-z

namespace std内添加内容是未定义的行为.

namespace std  // 建议修改命名空间, 不要放在`std`内
{
class threadpool
{
// ...
};
}

违反 C++ 标准的行为, C++ 标准明文规定:

"The behavior is undefined if any declaration is added to namespace std or to a namespace within std unless otherwise specified."
"向 std 命名空间或其子命名空间添加声明或定义是未定义行为,除非标准明确允许"

相关链接:
🔗 https://en.cppreference.com/w/cpp/language/extending_std
🔗 https://eel.is/c++draft/namespace.std
🔗 https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL58-CPP.+Do+not+modify+the+standard+namespaces

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions