am calling Form2 from Form1, and depending on the input in Form2, I want to enable/disable buttons in Form1 when I exit. However, because I need to call Form2 header before I define class Form1, Form1 is not defined when the compiler sees my call to it. If I therefore call Form1 header in Form2 header, then the compiler will see my call to Form2 before Form2 is defined!!.

Basically therefore, I wanna be able to call each form from each form, but have to define and make the call in one first.

This seems to me a very obvious thing to want to do, but I can't figure out myself how to do it, as you can't declare an extern class, or see any examples on the net of how to do it in Visual C++.net.

Any help appreciated, as is a real stumbling block for me.

UltimateNewbie

Well, I can think of a few solutions. One is to have a parent class of "AForm" that both Form1 and Form2 inherit from. Then both can refer to the .h file that AForm is defined in, no sweat.

Another is to use a forward declaration of form 2 in form 1's header file.

class Form2; // forward declaration
. . .
class Form1
{
public:
    TellForm1Something( Form1* pForm1 );
};

In this case, the forward declaration allows you to refer to a pointer to form1. You can't refer to form1 in a way that would require the compiler to know its size or contents, of course, but pointers to form1 are ok.

Hope this helps!

Oops! Too early in the morning to post; need more coffee. Here's what I MEANT to say:

class Form2; // forward declaration
. . .
class Form1
{
public:
    TellForm2Something( Form2* pForm2 );
};

Sheesh. Naru was right about me! Lazy AND stupid!

Sheesh. Naru was right about me! Lazy AND stupid!

There is no need to take Naru's comments too serious.

>There is no need to take Naru's comments too serious.
Anyone who takes me serious here is lazy, stupid, and foolish. :D;)

This article has been dead for over six months. Start a new discussion instead.