使用“类”声明变量关键字vs声明一个没有“类”函数签名中的关键字 [英] Declaring a variable with "class " keyword vs Declaring one without "class" keyword in function signatures

查看:437
本文介绍了使用“类”声明变量关键字vs声明一个没有“类”函数签名中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两种方法有什么区别?

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 function signatures, then if I add the keyword "class" in front of the respective variables, it can always solve this kind of compile-time errors.

例如,如果编译器无法识别

For example, if the compiler does not recognize the type Client in

void recv( Client * c )

那么如果我将它更改为

void recv( class Client * c )

问题解决了。

对不起,我不能提出一个具体的例子,因为我随机地提出这个问题。

I am sorry that I cannot come up with a concrete example as I randomly came up with this question.

推荐答案

在类型参数声明中使用关键字类,struct,enum称为精心设计的类型说明符。它在声明函数的范围中引入了新类型。
它类似于forward声明。

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 );

这篇关于使用“类”声明变量关键字vs声明一个没有“类”函数签名中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆