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

后端 未结 4 970
抹茶落季
抹茶落季 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 20:02

    Using keyword class, struct, enum in a type parameter declaration is called elaborated type specifier. It introduces the new type in the scope where the function is declared. It is similar to forward declaration.

    There is also another using of such a declaration. For example if a name of an object or a function name hides a class or enum with the same name. For example

    struct A {};
    
    A A; // now A is seen as an identifier of the object
    
    void f( struct A );
    

提交回复
热议问题