Direct link or declaration in C ++

How do I forward a link / declaration in C ++ to avoid circular heading references?

I have a #ifndef keeper in the header file, but memory tells me that I need this link for forwarding - which I used before> <but I don’t remember how.

+4
source share
3 answers

Imagine a class without including it. For instance:

//#include "Foo.h" // including Foo.h causes circular reference
class Foo;

class Bar
{
...
};
+15
source

I believe that the right term for what you are talking about is “forward declaration”. The "direct link" will be a bit confusing.

+1
source

, #ifndef. .

A direct link is used to avoid #include (ing) header files for objects that you use only with a pointer or link. However, in this case you do not solve the problem with the circular link, you just practice a good design and separate the .h file from the details that it does not need to know.

-2
source

All Articles