Declaring a variable with “class ” keyword vs Declaring one without “class” keyword in function signatures

后端 未结 4 965
抹茶落季
抹茶落季 2021-01-12 18:58

What is the difference between the two methods?

Sometimes when I get compile-time errors complaining that the compiler does not recognize some class types in functi

4条回答
  •  有刺的猬
    2021-01-12 19:56

    In this case

    void recv(Client * c)
    

    Compiler looks for declaration of Client. If it cannot find, it will give error. You can solve it by forward declaration as shown following

    class Client;
    void recv(Client * c)
    

    Although I have never seen second case, but it looks like that is also declaring class Client here.

提交回复
热议问题