VC++ multiple form problem

Hi,
I am trying to create multiple forms in vc++ Windows form application.
i have created two forms and i want to navigate from form1 to form2 and also form form2 to form1.

so i have included form1.h in form2.h
and form2.h in form1.h

i am getting compile time error:
1. undeclared idetified Form1
2. undeclared idetified Form2

can anybody help me?
These are circular dependencies. You need to use forward declaration for resolution. For example:

Form1.h
1
2
3
4
5
6
7
class Form2;  // forward declaration

class Form1    // definition
{
    Form2* form; // use
    //...
};


Form2.h
1
2
3
4
5
6
7
class Form1;  // forward declaration

class Form2    // definition
{
    Form1* form;  // use
    //...
};


Form1.cpp
1
2
3
#include "Form1.h"  // forward declaration of Form2
#include "Form2.h"  // definition of Form2
//... 


Form2.cpp
1
2
3
#include "Form2.h"  // forward declaration of Form1
#include "Form1.h"  // definition of Form1
//... 


You should always use forward declarations.
Last edited on
Topic archived. No new replies allowed.