
MT4・MT5 コンパイルエラー・警告 エラー(コンパイルできない)
arrays are passed by reference only
- エラー番号
error 294- 意味
- 配列は参照(&)でしか渡せない
「arrays are passed by reference only」とは
関数の引数に配列を受け取るとき、& を付けずに宣言したときのコンパイルエラーです。MQL では配列は必ず参照渡しにします。
MetaEditor での表示例
| MT4 | error 294: 'x' - arrays are passed by reference only |
|---|---|
| MT5 | error 294: arrays are passed by reference only |
実際のログでは先頭に「ファイル名(行,列) :」が付きます。ログの行をダブルクリックすると、エラーの場所にカーソルが移動します。表示は 2026年9月の MetaEditor で確認したもので、ビルドによって細部が変わることがあります。
「arrays are passed by reference only」の主な原因
- void f(int x[]) のように & を付けずに配列の引数を書いた
「arrays are passed by reference only」の対処法
- void f(int &x[]) のように & を付ける
- 中身を変更しないなら void f(const int &x[]) と書く
コード例(MQL5)
// 配列の引数には & を付ける(arrays are passed by reference only 対策)
// NG: double Sum(double values[])
double Sum(const double &values[]) // 変更しないなら const を付ける
{
double s = 0;
for(int i = 0; i < ArraySize(values); i++) s += values[i];
return s;
}
void Fill(double &values[], int n) // 中身を変えるなら const なし
{
ArrayResize(values, n);
ArrayInitialize(values, 0);
}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












