☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

违反 One Definition Rule

C++-Undefined-Behavior-10
目录 › next › previous

任何翻译单元不得包含变量、函数、类型、枚举或模板的多个定义,即 One Definition Rule,违反此规则会导致未定义的行为。

示例:

// In a.cpp
struct T {
    int i;
};

// In b.cpp
struct T {
    long i;    // Undefined behavior, violates One Definition Rule
};

依据

ISO/IEC 14882:2003 3.2(5)-undefined ISO/IEC 14882:2011 3.2(5)-undefined
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.