
MT4・MT5 コンパイルエラー・警告 警告(コンパイルは通る)
declaration hides global variable
- エラー番号
warning 62- 意味
- ローカル変数が同じ名前のグローバル変数を隠している
「declaration hides global variable」とは
関数の中で、グローバル変数と同じ名前の変数を宣言したときの警告です。関数の中ではローカル変数が優先されるため、グローバル変数を変えたつもりで変わっていない、というバグの原因になります。似た警告に「hides local variable」(番号61)があります。
MetaEditor での表示例
| MT4 | warning 62: declaration of 'x' hides global variable |
|---|---|
| MT5 | warning 62: declaration of 'x' hides global variable |
実際のログでは先頭に「ファイル名(行,列) :」が付きます。ログの行をダブルクリックすると、エラーの場所にカーソルが移動します。表示は 2026年9月の MetaEditor で確認したもので、ビルドによって細部が変わることがあります。
「declaration hides global variable」の主な原因
- グローバル変数と同じ名前の変数を関数の中で宣言した
- グローバル変数に代入するつもりで、先頭に int などの型を付けてしまった
- for 文のカウンタ i を二重に宣言した(hides local variable)
「declaration hides global variable」の対処法
- グローバル変数に代入したいなら、関数の中の型(int など)を消す
- グローバル変数には g_ などの接頭辞を付けて名前が重ならないようにする
コード例(MQL5)
// グローバル変数に代入するときは型を付けない(hides global variable 対策)
int g_count = 0; // グローバル変数には接頭辞を付けると重ならない
void CountUp()
{
// NG: int g_count = 1; ← 新しいローカル変数になり、グローバル変数は変わらない
g_count = g_count + 1;
}MetaEditor(MT5)でコンパイルできることを確認済みです。自分のEAに組み込むときは、変数名や設定値を合わせてください。
関連するエラー
コンパイルエラー・警告の解説一覧
- undeclared identifier
- semicolon expected
- unexpected token
- unexpected token, probably type is missing?
- some operator expected
- unexpected end of program
- unbalanced parentheses
- closing quote '"' expected
- wrong parameters count
- function already defined and has body
- variable already defined
- function must have a body
- function not defined
- not all control paths return a value
- function must return a value
- expression of 'void' type is illegal
- event handling function not found
- function declared with wrong type or/and parameters
- possible loss of data due to type conversion
- truncation of constant value
- implicit conversion from 'number' to 'string'
- return value of 'OrderSend' should be checked
- declaration hides global variable
- l-value required
- constant cannot be modified
- constant expression required
- invalid index value
- array required
- arrays are passed by reference only
- parameter conversion not allowed
- illegal operation use
- illegal 'else' without matching 'if'
- 'break' must be used within some loop or switch statement
- case value already used
- ambiguous call to overloaded function
- can't open include file
- unknown property
- identifier already used
- struct member undefined
- struct or class type expected
- private member access error
- cannot instantiate abstract class
- structures or classes containing objects are not allowed
- function declarations are allowed on global, namespace or class scope only
- name expected
- division by zero in the constant expression
- expression has no effect
- expression not boolean
- sign mismatch
- possible use of uninitialized variable
- empty controlled statement found
- macro redefinition
- call resolves to … due to new rules of method hiding
- cannot be used for static allocated array












