473,804 Members | 3,515 Online
Bytes | Software Development & Data Engineering Community
+ 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 1500
Hi,

You need to do something like:

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

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

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

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

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

Form2::GetSomet hingFromForm1()
{
// Implement
}

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

HTH,

Steve

"Mohit Gupta" <Mo********@dis cussions.micros oft.com> wrote in message
news:8B******** *************** ***********@mic rosoft.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
2852
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: "field `foo' has incomplete type" for the following code: #include <iostream> #include <vector>
2
3106
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: virtual String toString(); where String is defined as:
4
3286
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 application_management object (stores paths and other things, reads ini file of the application). Both needs to refer to each other -> application_management can write to a logger and logger needs to know the path of logger file. Of course, it's circular...
3
11677
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 instances of my C# classes. The problem I have is that I need to specify the class in my CoCreate call in C++. If I try to generate a TLB for the assembly that does contains the class and interface implementation, I end up with a circular...
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 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.
7
13527
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 dependencies). But then I started wondering how "easy" it would be to similarly make a NON-RUNTIME circular dependency between (implicitly linked) DLLs. Indeed authors like John Lakos, who focus on compile/link-time dependencies (not run-time),...
3
7059
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). I have set the jobstep to write to an output file "T:\out.txt". If the job is owned by an admin, it runs fine and writes the output file. If it is owned by a non-admin user, it gets the following error msg: Warning: cannot write logfile...
5
2959
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 them seem to work for me. Basically I've got the Component abstract class which is the base class for all elements like Buttons, Labels, CheckBoxes, Containers and so on. And every Component has a parent of type Container. But here is the thing,...
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5516
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2988
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.