What are the drawbacks of forward declaration?

前端 未结 5 1364
暗喜
暗喜 2021-01-14 13:09

I am wondering if there is any drawback for using forward declarations in all places when possible. This is if my header contains only declarations.

As far as I unde

5条回答
  •  悲&欢浪女
    2021-01-14 13:43

    The only drawback that comes to mind is that forward declarations require pointers. Therefore they may not be initialized and therefore could cause a null reference exception. As the coding standard that I currently use, requires all pointers require a null reference check if can add allot of code. I started to get around this with a Design By Contract invariants; then I can assert that anything initialized in the constructor never be null.

提交回复
热议问题