后增量和预增量超载 [英] Post-Increment and Pre-Increment Overloading

查看:64
本文介绍了后增量和预增量超载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好:


在C ++中,你必须在

重载时区分post和pre增量。有人能给我一个简短的演示,说明如何写这些吗?


我得到的印象是用相同的重载来处理的,但我是/ br / >
只是想确定。

Hello:

In C++, you had to distinguish between post and pre increments when
overloading. Could someone give me a short demonstration of how to
write these?

I get the impression that are handled with the same overload, but I
just want to make sure.

推荐答案

2007-11-11 17:10:07 -0800, " je ********** @ gmail.com"

< je ********** @ gmail.comsaid:
On 2007-11-11 17:10:07 -0800, "je**********@gmail.com"
<je**********@gmail.comsaid:

你好:


在C ++中,你必须在

重载时区分post和pre增量。有人能给我一个简短的演示,说明如何写这些吗?
Hello:

In C++, you had to distinguish between post and pre increments when
overloading. Could someone give me a short demonstration of how to
write these?



怎么写哪个? C ++版本?或者是C#版本?

How to write which? The C++ versions? Or the C# version?


我得到的印象是用相同的重载处理的,但是我想要确保它们是

I get the impression that are handled with the same overload, but I
just want to make sure.



据我所知,您的印象是正确的。你可以重载一个++

运算符。在你提出C ++行为之前,我甚至没有考虑过它可能会出现的其他可能性。

:)


请参阅 http://msdn2.microsoft.com/en -us / library / 8edha89s.aspx 了解更多

有关哪些运营商可能超载以及如何进行运营的详细信息。


Pete

As far as I know, your impression is correct. There is a single ++
operator you can overload. Until you brought up the C++ behavior, I
never even gave much thought to the possibility it might be otherwise.
:)

See http://msdn2.microsoft.com/en-us/library/8edha89s.aspx for more
details on which operators can be overloaded and how to go about it.

Pete


Peter Duniho< Np ********* @NnOwSlPiAnMk.com写在

新闻:2007111117592211272-NpOeStPeAdM @NnOwSlPiAnMkcom:
Peter Duniho <Np*********@NnOwSlPiAnMk.comwrote in
news:2007111117592211272-NpOeStPeAdM@NnOwSlPiAnMkcom:

2007-11-11 17:10:07 -0800,je ********** @ gmail.com ;

< je ********** @ gmail.comsaid:
On 2007-11-11 17:10:07 -0800, "je**********@gmail.com"
<je**********@gmail.comsaid:

>您好:

在C ++中,你必须在
重载时区分post和pre增量。有人能给我一个简短的演示,说明如何写这些吗?
>Hello:

In C++, you had to distinguish between post and pre increments when
overloading. Could someone give me a short demonstration of how to
write these?



怎么写哪个? C ++版本?或者C#版本?


How to write which? The C++ versions? Or the C# version?


>我得到的印象是使用相同的重载处理,但我只是想确认。
>I get the impression that are handled with the same overload, but I
just want to make sure.



据我所知,你的印象是正确的。你可以重载一个++

运算符。在你提出C ++行为之前,我甚至没有考虑过它可能出现的其他可能性。
:)


见< a rel =nofollowhref =http://msdn2.microsoft.com/en-us/library/8edha89s.aspxtarget =_ blank> http://msdn2.microsoft.com/en-us/library /8edha89s.aspx 了解更多

有关哪些运营商可能超载以及如何进行运营的详细信息。


Pete


As far as I know, your impression is correct. There is a single ++
operator you can overload. Until you brought up the C++ behavior, I
never even gave much thought to the possibility it might be otherwise.
:)

See http://msdn2.microsoft.com/en-us/library/8edha89s.aspx for more
details on which operators can be overloaded and how to go about it.

Pete



我不知道.Net-land,但在原生C ++中,前/后增量

运算符是2个独立的运算符。 />

class xyzzy

{

....

xyzzy& operator ++()//前缀

{

// todo:递增此

返回* this;

}

xyzzy operator ++(int)// postfix

{

xyzzy tmp(* this);

// todo:增加这个

返回tmp;

}

};


Dave Connet

I don''t know about .Net-land, but in native C++, the pre/post-increment
operators are 2 separate operators.

class xyzzy
{
....
xyzzy& operator++() // prefix
{
// todo: increment this
return *this;
}
xyzzy operator++(int) // postfix
{
xyzzy tmp(*this);
// todo: increment this
return tmp;
}
};

Dave Connet


2007-11-11 19:37:31 -0800,David Connet< co **** @ entelos.comsaid:
On 2007-11-11 19:37:31 -0800, David Connet <co****@entelos.comsaid:

我不知道.Net-land,但在原生C ++中,前/后增量

运算符是2个独立的运算符。
I don''t know about .Net-land, but in native C++, the pre/post-increment
operators are 2 separate operators.



是的,当然是。 OP和我都承认这一点。而且我认为如果OP要求如何在C ++中声明这样的话,那么你的帖子

将与那个问题相关(但不是我要求的那个) -topic

这个新闻组)。

Yes, of course they are. Both the OP and I acknowledged that. And I
suppose if the OP is asking for how to declare such in C++, your post
would be relevant to that question (but not what I''d call on-topic in
this newsgroup).


这篇关于后增量和预增量超载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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