开发者

including files problem

I have test.h file and example.h file and I w开发者_StackOverflowant to include each one in the other I tried the following but didn't work.

In file test.h:

 #ifndef "example.h"

 #define "example.h"`

...

 #endif

And in file example.h :

#include "test.h"

And later tried :

#ifndef "test.h"

 #define "test.h"

...

#endif

But nothing worked.


You need to come up with some unique identifiers for each include guard. For example:

#ifndef EXAMPLE_H
#define EXAMPLE_H
...
#endif

You can't just use the filenames with #ifndef etc.


Maybe you should write like below:

In file test.h:

#ifndef __TEST_H__
#define __TEST_H__
#include "example.h"
#endif// __TEST_H__

In file example.h:

#ifndef __EXAMPLE_H__
#define __EXAMPLE_H__
#include "test.h"
#endif//__EXAMPLE_H__


You can't. This way goes to circular include hell. Resolve your problem by defining structures you use

example.h

class bar;

    class foo
    {
        bar* barPtr;
    }

test.h

class foo;

class bar 
{
    foo* fooPtr;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜