473,387 Members | 3,810 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,387 software developers and data experts.

looped include

Hi, I have a problem....
I can show you what this is about in an example:
There are 4 files:

a.c:
#include "a.h"

int main() {

B* b = new B();
A* a = new A();

a->bref = b;
b->aref = a;

b->aref->test();
a->bref->test();
return 0;
}

b.c:
#include "b.h"

a.h:
#ifndef A_H
#define A_H
#include "b.h"

#include <stdio.h>
#include <stdlib.h>

class B;
class A {
public: B* bref;
public: A() {;}
public: void test()
{
printf ("test in A\n");
bref->test();
}
};

#endif

b.h:
#ifndef B_H
#define B_H
#include "a.h"

#include <stdlib.h>
#include <stdio.h>

class A;
class B {
public: A* aref;
public: B() {;}
public: void test() { printf ("test in B\n"); }
};

#endif

Why does this not compile? I get errors in line with code: bref-
>test(); in a.h
PLEASE help.

regards,
--
LS

Oct 7 '07 #1
5 1275
Dragilla wrote:
Hi, I have a problem....
I can show you what this is about in an example:
There are 4 files:

a.c:
#include "a.h"

int main() {

B* b = new B();
A* a = new A();

a->bref = b;
b->aref = a;

b->aref->test();
a->bref->test();
return 0;
}

b.c:
#include "b.h"

a.h:
#ifndef A_H
#define A_H
#include "b.h"

#include <stdio.h>
#include <stdlib.h>

class B;
// class B;
not needed
class A {
public: B* bref;
public: A() {;}
public: void test()
{
printf ("test in A\n");
bref->test();
}
};

#endif

b.h:
#ifndef B_H
#define B_H
#include "a.h"
//#include "a.h"
not needed
>
#include <stdlib.h>
#include <stdio.h>

class A;
class B {
public: A* aref;
public: B() {;}
public: void test() { printf ("test in B\n"); }
};

#endif

Why does this not compile? I get errors in line with code: bref-
>test(); in a.h
PLEASE help.

regards,
Oct 7 '07 #2
Ok, that worked, thanks alot.
But if I modify my files like you said and add some code, so that
class B looks like this:
class B {
public: A* aref;
public: B() {;}
public: void test()
{
printf ("test in B\n");
aref->test2;
}
};

and add function test2 to class A, i get a whole new bunch of
errors....

Actually my problem concerns Windows Forms i VC++ in .Net 2003.
I have a main form Form1 and 2 other forms i need to show/hide from
the main form.
Then i need the data from the other 2 forms back into the Form1.
I can't get it to work... Any standart solution to this?

regards,
--
LS
Oct 7 '07 #3
Dragilla wrote:
Ok, that worked, thanks alot.
But if I modify my files like you said and add some code, so that
class B looks like this:
class B {
public: A* aref;
public: B() {;}
public: void test()
Repeating "public:" multiple times doesn't get it more public than it
already is ;-)
{
printf ("test in B\n");
aref->test2;
}
};

and add function test2 to class A, i get a whole new bunch of
errors....
Don't put the implementation into the header file.

Oct 7 '07 #4
Rolf Magnus wrote:
Dragilla wrote:
>Ok, that worked, thanks alot.
But if I modify my files like you said and add some code, so that
class B looks like this:
class B {
public: A* aref;
public: B() {;}
public: void test()

Repeating "public:" multiple times doesn't get it more public than it
already is ;-)
Probably a java-ism (or a C#ism)
Oct 7 '07 #5
On 7 Pa , 15:37, Rolf Magnus <ramag...@t-online.dewrote:
and add function test2 to class A, i get a whole new bunch of
errors....

Don't put the implementation into the header file.
Yes, that's what i did :) and that's the soultion :)
Thanks.
Oct 7 '07 #6

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

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
0
by: lotmr | last post by:
After figuring out how to have a threaded frontend to pass varibles I've run into a problem. The 'quit' command works as long as issue it fast enough as soon as the if's start looping. If I wait...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
9
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ...
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...
1
by: ya man | last post by:
when i use #include <iostream.h> in some files i get lots of error messages of the kind 'ambiguous symbol this is solved when i use #include <iostream why is that ? and can i use #include...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
16
by: haft | last post by:
I have posted this question on a javascript forum as it contains javascript code however it was believed to be an asp issue. The following head section javascript code contains the function...
6
by: MrDeej | last post by:
Hello! I have code wich scans the through 10 computers on a LAN for files and import them into different tabels. This code aproximitly imports 10 000 files (with 1 to 20 rows of info) a day and is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.