Forward Declaration of Class, Function

前端 未结 6 1114
夕颜
夕颜 2021-01-04 19:26

When forward declarations of functions work in a source file (.cpp), why would the same doesn\'t work for classes ?

Thanks.

// main.cpp

void forwar         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 19:57

    The compiler reads stuff from beginning to end, and generates code as it goes. (Some compilers may not do this, but they should behave as if they did.) But before the class is defined, the compiler doesn't know that One::statVar or One::anyAccess should exist, or whether the function is virtual, static, or what. It needs to know that stuff in order to generate code.

提交回复
热议问题