What are the dangers of forward declarations?

前端 未结 9 1426
轻奢々
轻奢々 2021-02-01 16:58

I just had an interview. I was asked what is a \"forward declaration\". I was then asked if they were dangers associated with forward declarations.

I could not answer to

9条回答
  •  醉酒成梦
    2021-02-01 17:13

    The first way is to reorder our function calls so add is defined before main:

    That way, by the time main() calls add(), it will already know what add is. Because this is such a simple program, this change is relatively easy to do. However, in a large program, it would be extremely tedious trying to decipher which functions called which other functions so they could be declared in the correct order.

提交回复
热议问题