編譯程式警告 (層級 4) C4458
'identifier' 的宣告會隱藏類別成員
本機範圍中的標識碼宣告會隱藏類別範圍中同名標識碼的宣告。 此警告可讓您知道,此範圍中標識符的參考會解析為本機宣告的版本,而不是類別成員版本,這可能不是您的意圖。 若要修正此問題,建議您提供與類別成員名稱不衝突的局部變數名稱。
範例
下列範例會產生 C4458,因為 中的 參數x
和局部變數y
member_fn
的名稱與 類別中的數據成員相同。 若要修正此問題,請針對參數和局部變數使用不同的名稱。
// 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;