Questions from a "dummy" - page 139

 
220Volt:
Yeah, I guess I should give it a plus sign ))
Good illustration of the pointlessness of the "why?" question. Maybe there are other questions? :)
 
MetaDriver:
Good illustration of the pointlessness of the "why?" question. Maybe there are other questions? :)
:) Here's a thought - maybe there should be some other way to do it in VS? Or is it useless?
 
220Volt:
:) A thought - is there some other way to do it in VS? Or is it useless?
That's the right question, and a useful one. Now the experts can give you a meaningful answer... :)
 
220Volt:
:) I have an idea - maybe VS should have a different way of doing things?
yes.
 
//--------- 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;}

 
sergeev:
Yeah.
Well, anyone can do it... you make the reference variables work... :) :)
 
MetaDriver:

There you go, the plus one's off :). Thank you.
 
sergeev:
yes.

By the way, that doesn't work either:

class cl2; 

class cl1
{
public:
        int q;
        void fn2(cl2 *t){t->i = 87;}
};


class cl2
{
public:
        int i;
        void fn(cl1 *w){w->q = 9;}
};

This is how it works:

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;}

220Volt:
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:

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.