473,480 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Forward Linking and Circular Dependency problem

Hi all,

I have just started working on VC++ .Net and have problem with circular
dependencies of 2 files.

I created 2 forms "Form1" and "Form2", which respectively created 2 .h
files, Form1.h and Form2.h and so as 2 classes, "Form1" and "Form2".

Now I want to use object of Form1 inside Form2 and object of Form2 in Form1.

Reason:

1) I want to open Form2 from Form1 when a button is clicked
2) Want to access some public variable in Form1 from Form2.

I all the time get compiling error stating that Form1 is not declared even
if I have included "form1.h" and "form2.h" in "form2.h" and "form1.h",
respectively.

May I know how to solve this problem.

Your help will be appreciated.

Thanks
Jul 21 '05 #1
1 1469
Hi,

You need to do something like:

// In Form1.h
#include "Form2.h"

__gc class Form1
{
public:
void GetSomethingFromForm2() { .... }
};

// In Form2.h
__gc class Form1; // Don't define or include it.

__gc class Form2
{
void GetSomethingFromForm1(); // Don't implement here
};

// In Form2.cpp
#include "Form1.h"

Form2::GetSomethingFromForm1()
{
// Implement
}

This way you'll forward declare Form1 in Form2, but you won't get a circular
dependency.

HTH,

Steve

"Mohit Gupta" <Mo********@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
Hi all,

I have just started working on VC++ .Net and have problem with circular
dependencies of 2 files.

I created 2 forms "Form1" and "Form2", which respectively created 2 .h
files, Form1.h and Form2.h and so as 2 classes, "Form1" and "Form2".

Now I want to use object of Form1 inside Form2 and object of Form2 in Form1.
Reason:

1) I want to open Form2 from Form1 when a button is clicked
2) Want to access some public variable in Form1 from Form2.

I all the time get compiling error stating that Form1 is not declared even
if I have included "form1.h" and "form2.h" in "form2.h" and "form1.h",
respectively.

May I know how to solve this problem.

Your help will be appreciated.

Thanks

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2829
by: Markus Dehmann | last post by:
I have a circular dependency between two classes. The FAQ hint about a forward declaration does not help in my case ( How can I create two classes that both know about each other?) Error:...
2
3085
by: ernesto basc?n pantoja | last post by:
Hi everybody: I'm implementing a general C++ framework and I have a basic question about circular dependencies: I am creating a base class Object, my Object class has a method defined as:...
4
3269
by: Henke | last post by:
I have this scenario. public class A { public int numbers; public class A() { }
2
761
by: Rimma Meital via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Rimma Meital I have 2 DLLs (Class Libraries). Both defines single-ton objects - logger object (writes to logger) and...
3
11637
by: François Côté | last post by:
I'm generating a TLB from one of my assemblies that contains an interface declaration. The class that implements this interface is in another assembly. I import this tlb in my C++ code to create...
1
262
by: Mohit Gupta | last post by:
Hi all, I have just started working on VC++ .Net and have problem with circular dependencies of 2 files. I created 2 forms "Form1" and "Form2", which respectively created 2 .h files, Form1.h...
7
13500
by: barias | last post by:
Although circular dependencies are something developers should normally avoid, unfortunately they are very easy to create accidentally between classes in a VS project (i.e. circular compile-time...
3
7028
by: donnyma | last post by:
I have a problem that looks like it has not been discussed before in these groups. I have a simple SQLAgent job that runs sp_who (could be anything, but let's just say sp_who for this example). ...
5
2942
by: fomas87 | last post by:
Hi guys, I'm writing a framework for an sdl gui in c++, but got stuck on the circular dependency, I've read a lot of articles about resolving dependencies and about forward declaration but none of...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.