473,320 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Cross include headers

Hi all,

Can anyone tell me how I can include one header Form1.h into another
header Form2.h and the other way around without evolving into compile
errors? Both headers contain only one class in which I want to declare
an instance of the class in the other header file.

I assume that through some circulair reference this won't work, but I
don't know how otherwise to be able to declare the instances. The
compile error that I receive is:

1>Proj1.cpp
1>d:\Form2.h(26) : error C2143: syntax error : missing ';' before '^'
1>d:\Form2.h(26) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form2.h(26) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form2.h(35) : error C2065: 'f1' : undeclared identifier
1>d:\Form2.h(35) : error C2061: syntax error : identifier 'Form1'
1>Form2.cpp
1>d:\Form1.h(25) : error C2143: syntax error : missing ';' before '^'
1>d:\Form1.h(25) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form1.h(25) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form1.h(34) : error C2065: 'f2' : undeclared identifier
1>d:\Form1.h(34) : error C2061: syntax error : identifier 'Form2'

These file are part of a VS2006 project and both the classes in the
different files are part of the same namespace.

I was able to succesfully "cross include" the header Form1.h into the
source file belonging to Form2.h (Form2.cpp), but this doesn't give me
the ability to declare the class from Form1.h in Form2.h.

What is the right way to go here, this solution should be simple right?

Thanks in advance, Maart

Oct 26 '06 #1
6 2238
Maart_newbie wrote:
Hi all,

Can anyone tell me how I can include one header Form1.h into another
header Form2.h and the other way around without evolving into compile
errors? Both headers contain only one class in which I want to declare
an instance of the class in the other header file.

I assume that through some circulair reference this won't work, but I
don't know how otherwise to be able to declare the instances. The
compile error that I receive is:

1>Proj1.cpp
1>d:\Form2.h(26) : error C2143: syntax error : missing ';' before '^'
1>d:\Form2.h(26) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form2.h(26) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form2.h(35) : error C2065: 'f1' : undeclared identifier
1>d:\Form2.h(35) : error C2061: syntax error : identifier 'Form1'
1>Form2.cpp
1>d:\Form1.h(25) : error C2143: syntax error : missing ';' before '^'
1>d:\Form1.h(25) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form1.h(25) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
1>d:\Form1.h(34) : error C2065: 'f2' : undeclared identifier
1>d:\Form1.h(34) : error C2061: syntax error : identifier 'Form2'

These file are part of a VS2006 project and both the classes in the
different files are part of the same namespace.

I was able to succesfully "cross include" the header Form1.h into the
source file belonging to Form2.h (Form2.cpp), but this doesn't give me
the ability to declare the class from Form1.h in Form2.h.

What is the right way to go here, this solution should be simple right?

Thanks in advance, Maart
Maart:

You need to learn about forward declaration in C++.

// Form2.h

#pragma once

class Form1; // forward declaration

class Form2 // class definition
{
Form1* m_pForm1;
};

// Form2.cpp

#include "Form1.h"
#include "Form2.h"

If Form1 is only used as a pointer in the definition of Form2, the
compiler does not need to see the definition of class Form1 in order to
compute the layout of class Form2.

David Wilkinson
Oct 26 '06 #2
Thanks David!

That was exactly what I neaded to know!

Oct 26 '06 #3
Hi Maart,

"Maart_newbie" <ma****@netscape.netwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hi all,
These file are part of a VS2006 project and both the classes in the
different files are part of the same namespace.
I want VS2006, too. Where did you get it ;)

--
SvenC
Oct 26 '06 #4
I want VS2006, too. Where did you get it ;)

http://www.microsoft.com/downloads/i...splayLang%3den
>
--
SvenC

Oct 26 '06 #5
"Ben Voigt" <rb*@nospam.nospamwrote in message
news:Oe****************@TK2MSFTNGP02.phx.gbl...
>I want VS2006, too. Where did you get it ;)

http://www.microsoft.com/downloads/i...splayLang%3den
;-)

--
SvenC
Oct 27 '06 #6
;-)->2005

Oct 31 '06 #7

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

Similar topics

2
by: George Zhou | last post by:
Such as in a.h, I need put #include "b.h", while in b.h, I need put #include "a.h", but it does not work! Any alternative way to do it?
12
by: Santiago de Compostela | last post by:
Hi The following program doesn't compile on MS VC++ or Bloodshed Dev-C++ #include <iostream> int strlen(const char *in) {
2
by: Aguilar, James | last post by:
Suppose I have classes Foo and Bar. They depend on each other, but other classes also depend on them. Moreover, their functionality is distinct. How can I include both of them? Specifically,...
8
by: Ian Malone | last post by:
Sorry if this is a FAQ, but I had a quick look through the FAQ Lite and couldn't see it. Googling gives inconsistent answers. I'm coming from a C background. In C if I want to use command...
6
by: atv | last post by:
Alright, i have some questions concerning include files en global variables.I hope someone is willing to answer these. 1).Why is it that if i define a global variable in a file, say main.c, and...
5
by: copx | last post by:
How do I include headers which are in a sub directory (not in my main src dir)? I use a scripting language - Lua - to extend my C app and all the Lua code is in the subdirectory \lua. I want to...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
3
by: clinisbut | last post by:
may be i'm asking a stupid question, but, is it possible to include a header file at runtime?? I have some header files with this inside: {{12, 16},{ 0x00,0x00, /* ................ */...
2
by: vjayis | last post by:
hi i m using mail() function to send mails and it works well for an sample message without including headers., when i include headers and send an html content or an sample content i didnt receive...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.