Forward Declaration of Class, Function

前端 未结 6 1111
夕颜
夕颜 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 20:03

    You're getting the error message on int One:: statVar = 10 ; NOT on the forward declaration, which is fine.

    The compiler needs to know the full definition of the class before you can define static members like that - a forward declaration is insufficient (it needs to be able to confirm that the type is correct from the class definition).

    You'll need to move your static attribute definition below the class definition.

提交回复
热议问题