关于评估订单的问题 [英] Question about evaluation order

查看:59
本文介绍了关于评估订单的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我对C ++中的评估顺序有一个非常具体的问题。

假设某种自定义数组类,带有超载的下标

运算符。在以下代码中:


{

my_array a,b,c;


a [6] = b [5] + c [4];

}


我会假设以下顺序:


1 )下标运算符被评估为''b''和''c'',两者都是
返回一个引用(例如,double&)
2)调用operator,返回一个临时对象

3)下标运算符被评估为'a'',返回一个引用。

4)=运算符被计算。


我的问题:这是事情的方式,还是这个命令没有定义在

C ++中?更具体一点:a(步骤3)的下标评估是否可能已经在步骤1中完成(在添加运算符之前)?


Thanx,

Jeroen

解决方案

Jeroen写道:
< blockquote class =post_quotes>
更具体一点:a(步骤3)的下标评价是否可能已经在步骤1中完成(在此之前) add-operator)?



是的。


-


- - Pete

Roundhouse Consulting,Ltd。( www.versatilecoding.com

标准C ++库扩展:教程和
参考的作者。 ( www.petebecker.com/tr1book


Pete Becker schreef:


Jeroen写道:


>要更多具体:是否有可能在步骤1中(在添加运算符之前)完成了对'a''(步骤3)的下标评估?



是。



谢谢皮特!这使我无法完成一个实现,即

最终不起作用....




Jeroen < no ***** @ thanx.comwrote in message news:45e57267


Hi all,

I''ve got a very specific question about the evaluation order in C++.
Assume some kind of custom array class, with an overloaded subscript
operator. In the following code:

{
my_array a, b, c;

a[6] = b[5] + c[4];
}

I would assume the following order:

1) The subscript operators are evaluated for ''b'' and ''c'', both
returning a reference (double& for example)
2) The add-operator is called, returning a temporary object
3) The subscript operator is evaluated for ''a'', returning a reference.
4) The = operator is evaluated.

My question: is this the way things go, or is this order not defined in
C++? To be more specific: is it possible that the subscript evaluation
for ''a'' (step 3) is done already in step 1 (before the add-operator)?

Thanx,

Jeroen

解决方案

Jeroen wrote:

To be more specific: is it possible that the subscript evaluation
for ''a'' (step 3) is done already in step 1 (before the add-operator)?

Yes.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)


Pete Becker schreef:

Jeroen wrote:

>To be more specific: is it possible that the subscript evaluation for
''a'' (step 3) is done already in step 1 (before the add-operator)?


Yes.

Thanks Pete! That keeps me from working out an implementation that
doesn''t work in the end....



"Jeroen" <no*****@thanx.comwrote in message news:45e57267


这篇关于关于评估订单的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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