Why are forward declarations necessary?
Posted
by user199421
on Stack Overflow
See other posts from Stack Overflow
or by user199421
Published on 2010-04-13T19:32:33Z
Indexed on
2010/04/13
19:43 UTC
Read the original article
Hit count: 222
In languages like C# and Java there is no need to declare (for example) a class before using it. If I understand it correctly this is because the compiler does two passes on the code. In the first it just "collects the information available" and in the second one it checks that the code is correct.
In C and C++ the compiler does only one pass so everything needs to be available at that time.
So my question basically is why isn't it done this way in C and C++. Wouldn't it eliminate the needs for header files?
© Stack Overflow or respective owner