//--------- C++
class cl2;
class cl1
{
public:
int q;
void fn2(cl2 &t);
};
class cl2
{
public:
int i;
void fn(cl1 &w);
};
//-- реализация функций только после полного описания интерфейса - т.е. фиксации размеров классов
//-- теперь компилятор знает сколько именно стека нужно резервировать в функциях под классы
void cl1::fn2(cl2 &t){t.i = 87;}
void cl2::fn(cl1 &w){w.q = 9;}
class cl2;
class cl1
{
public:
int q;
void fn2(cl2 *t);//{t->i = 87;} // здесь реализация не прокатит: ещё неизвестен размер и состав класса cl2
}; // например, откуда последовательному компилятору знать о члене 'i' ?
class cl2
{
public:
int i;
void fn(cl1 *w){w->q = 9;} // размер и состав класса cl1 уже известен на этом этапе. поэтому можно здесь.
};
void cl1::fn2(cl2 *t){t->i = 87;}
//void cl2::fn(cl1 *w){w->q = 9;}
The main thing to remember is that C++ rules are designed to compile sequentially.
220Volt: It compiles in MQL without errors, it won't compile in VS (the programmer is telling the programmer that he/she is unable to use the class without definition). Why?
VS is right of course. The declaration will suffice if you take the fn2 function implementation outside the class and after the cl2 definition.
Since the function is defined right in the body, a simple declaration does not work (although passing by reference), because cl2 definition is required for the function to work.
Either a bug or a bug. Most likely it is the latter, but better to clarify.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Yeah, I guess I should give it a plus sign ))
Good illustration of the pointlessness of the "why?" question. Maybe there are other questions? :)
:) A thought - is there some other way to do it in VS? Or is it useless?
:) I have an idea - maybe VS should have a different way of doing things?
Yeah.
yes.
By the way, that doesn't work either:
This is how it works:
There you go, the plushie's off :). Thank you.
No, no, no, no! Keep the plus. "MS sucks, MQ is king!"
You can also go like this:
The main thing to remember is that C++ rules are designed to compile sequentially.VS is right of course. The declaration will suffice if you take the fn2 function implementation outside the class and after the cl2 definition.
Since the function is defined right in the body, a simple declaration does not work (although passing by reference), because cl2 definition is required for the function to work.
Either a bug or a bug. Most likely it is the latter, but better to clarify.