-
Using multiple files
I have a question about a problem that I've been having that gets in the way of development. Say I have file a.h, and file b.h.
File b.h contains:
Code:
class x {
public:
y obj_y;
};
and file a.h contains:
Code:
class y {
public:
x obj_x;
};
#include-ing them to each other causes an #include loop. Is there any way around this?
Thanks for the help,
Valar_King
-
Bad idea from me....delete delete delete
-
One of them will have to contain a pointer to the other, otherwise the data structure expands recursively.
In one or two files, you can do this
Code:
class y; // a forward declaration
class x {
public:
y *obj_y;
};
class y {
public:
x obj_x;
};
-
how do i use one class or function from another file?
-
Like this?
File b.h contains:
Code:
class y; // a forward declaration
class x {
public:
y *obj_y;
};
File a.h contains:
Code:
#include "b.h"
class y {
public:
x obj_x;
};