演员无效??? [英] Cast to void???

查看:57
本文介绍了演员无效???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Loki(smartptr.h)中,我注意到以下表达式由

本身发生:


(void)val;


使某些内容无效的目的是什么,特别是在这样的单独表达式中,而不是作为更大的一部分的一部分?

我很惊讶这是可能的,因为无法声明类型为void的变量

。我很想学习目的...


这是我在上面看到的背景:


static void OnDereference(P val)

{assert(val); (空隙)VAL; }


BTW,我在Loki的VC ++端口看到这个。我不知道它是否在

原版Loki中......


谢谢,

Dave

In Loki (smartptr.h), I''ve noticed the following expression occurring by
itself:

(void)val;

What is the purpose in casting something to void, especially in a
stand-alone expression such as this and not as part of something larger?
I''m surprised this is possible as it is not possible to declare a variable
of type void. And I''m intrigued to learn the purpose...

Here''s the context I see this in:

static void OnDereference(P val)
{ assert(val); (void)val; }

BTW, I see this in the VC++ port of Loki. I don''t know if it''s in the
original Loki or not...

Thanks,
Dave

推荐答案

Dave Theese写道:
Dave Theese wrote:
在Loki(smartptr.h)中,我注意到以下表达式单独发生:

(void)val;

使某些内容无效的目的是什么,特别是在
独立表达式中比如这个而不是作为更大的东西的一部分?我很惊讶这是可能的,因为不可能声明一个void类型的变量。我很想学习
目的......
In Loki (smartptr.h), I''ve noticed the following expression occurring
by itself:

(void)val;

What is the purpose in casting something to void, especially in a
stand-alone expression such as this and not as part of something
larger? I''m surprised this is possible as it is not possible to
declare a variable of type void. And I''m intrigued to learn the
purpose...



[SNIP]


我第一次看到这个和我能想象的唯一原因就是避免编译

时间警告未使用的变量。


-

WW aka Attila


[SNIP]

First time I see this and the only reason I can imagine is to avoid compile
time warnings for unused variables.

--
WW aka Attila


> Dave Theese写道:
> Dave Theese wrote:
在Loki(smartptr.h)中,我注意到以下表达单独出现

(void)val;

什么是使某些东西无效的目的,特别是在这样的独立表达中,而不是作为某种东西的一部分
更大?我很惊讶这是可能的,因为不可能声明一个void类型的变量。我很想学习
目的... [SNIP]

我第一次看到这个,我能想象的唯一原因就是避免
In Loki (smartptr.h), I''ve noticed the following expression occurring
by itself:

(void)val;

What is the purpose in casting something to void, especially in a
stand-alone expression such as this and not as part of something
larger? I''m surprised this is possible as it is not possible to
declare a variable of type void. And I''m intrigued to learn the
purpose... [SNIP]

First time I see this and the only reason I can imagine is to avoid


未使用变量的编译时警告。


compile time warnings for unused variables.




不需要这个。可以简单地省略未使用的参数名称。



No need for this however. An unused parameter name can simply be omitted.


John Almer写道:

[SNIP]
John Almer wrote:
[SNIP]

我第一次看到这个,我能想象的唯一原因就是避免对未使用的变量进行编译时警告。

First time I see this and the only reason I can imagine is to avoid
compile time warnings for unused variables.



不需要但是这个。可以简单地省略未使用的参数名称。



No need for this however. An unused parameter name can simply be
omitted.




是。但是我谈到了一个参数吗?


这是模板元编程魔法的深层内容。我很容易想象它

是在某些情况下不用于函数的某种变量。


-

WW又名阿提拉



Yes. But did I talk about a paramneter?

It is deep inside template metaprogramming magic. I can easily imagine it
was some sort of variable not used in a function in certain cases.

--
WW aka Attila


这篇关于演员无效???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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