## Recommended Posts

dave    2187
Thats simply it, this returns erros in VC6 Hows this solved? ace

##### Share on other sites
mldaalder    193

// Code
#endif

Well, include similar tags around the #include statements.

//Header1:#ifndef HEADER1_H#define HEADER1_H#ifndef HEADER2_H#include"Header2.h"#endif// Rest of code#endif//Header2:#ifndef HEADER2_H#define HEADER2_H#ifndef HEADER1_H#include"Header1.h"#endif// Rest of code#endif

But the best way (well I think it is). Is to try and prevent these kind of loops.

##### Share on other sites
dave    2187
The problem is that i want to pass a pointer to a function into the other class, but since the pointer is of type class1, class2 needs the class1 header so it can recieve it,

##### Share on other sites
liquidAir    314
I believe header files should be this way:

#ifndef HEADER#define HEADER// header file contents#endif

Or maybe you have defined variables in the header files, and it complains about the objects already being defined in so-so file. It is more advisable to define your variables in the source files, not header files.

##### Share on other sites
Ok, then create a forward declaration of class1, then in the source file include the header with the definition. ( I think I got declare/define the right way round, I do tend to mix them up ).

##### Share on other sites
Ok, just to clarify here, you have something like this:
class1 - does... something.class2 - has the function that needs a class1::somefunction pointer

How does class1 need class2?

Oluseyi    2116

##### Share on other sites
Charles B    863
It's called a cyclic dependency. Avoid it as much as possible, not only for headers, but also classes, modules etc... The less you have the better your code is architectured. You can use call backs very often to keep your code modular.

##### Share on other sites
Mussi    4409
You could also do:

#pragma once

#endif

##### Share on other sites
Guest Anonymous Poster
Quote:

Yes, you could use #pragma once instead of include guards if you want to write invalid C++ code.

##### Share on other sites
silvermace    634
sounds like you need a forward declartion here
// ********* header2.hclass A {  ...};// ********* header1.hclass A;class B {public:   void foo(A *lpA);};

##### Share on other sites
silvermace    634
Quote:

pragma once does not guarantee that the file will not get included again, it simply guarantees that the preprocessor will not read the file again.