编译器警告(等级 4)C4458

“identifier”的声明隐藏了类成员

本地范围内的 identifier 声明隐藏了类范围内同名 identifier 的声明。 此警告指示在此范围中对 identifier 的引用将解析为本地声明的版本,而不是类成员版本,这可能是你的意图,也可能不是。 若要解决此问题,建议你提供不与类成员名称冲突的局部变量名称。

示例

以下示例生成 C4458,因为参数 xmember_fn 中的局部变量 y 与类中的数据成员具有相同的名称。 若要解决此问题,请为参数和局部变量使用不同的名称。

// C4458_hide.cpp
// compile with: cl /W4 /c C4458_hide.cpp

struct S {
    int x;
    float y;
    void member_fn(long x) {   // C4458
        double y;  // C4458
        y = x;
        // To fix this issue, change the parameter name x
        // and local name y to something that does not
        // conflict with the data member names.
    }
} s;