为什么重载运算符。 (会员运营商)被禁止? [英] Why is overloading operator. (member operator) forbidden?

查看:47
本文介绍了为什么重载运算符。 (会员运营商)被禁止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我想知道,为什么重载运算符。 (期间)被禁止?它可以让一些奇怪的应用程序成为可能(动态继承和

透明的远程方法调用在我脑海中浮现)并且它会相当于

通用的。我能看到的唯一侧面是那个操作符。

本身不会通过运算符查找。 。


我读到之前有关于这个问题的辩论,但是我没有能够找到它被拒绝的原因。

我把这条消息发送到Boost邮件列表,但是他们错误地将他们转介给了我。使用网络。


谢谢,


彼得

Hello,

I was wondering, why is overloading operator. (period) forbidden? It
would make a few odd applications possible (dynamic inheritance and
transparent remote method invocation spring to my mind) and it would
be fairly generic. The only sidecase I can see is that operator.
itself would not be looked up through operator. .

I read that there was previous debate on the subject, but I haven''t
been able to find why it was rejected.

I sent this message to the Boost mailing list, in error, they referred
me to Usenet.

Thanks,

Peter

推荐答案

On 14 Maj,07:36,dasca。 .. @ gmail.com" < dasca ... @ gmail.comwrote:
On 14 Maj, 07:36, "dasca...@gmail.com" <dasca...@gmail.comwrote:

你好,


我想知道,为什么重载运算符。 (期间)被禁止?它可以让一些奇怪的应用程序成为可能(动态继承和

透明的远程方法调用在我脑海中浮现)并且它会相当于

通用的。我能看到的唯一侧面是那个操作符。

本身不会通过运算符查找。 。


我读到之前有关于这个问题的辩论,但是我没有能够找到它被拒绝的原因。

我把这条消息发送到了Boost邮件列表,但是他们错误地将他们推荐给了Usenet。
Hello,

I was wondering, why is overloading operator. (period) forbidden? It
would make a few odd applications possible (dynamic inheritance and
transparent remote method invocation spring to my mind) and it would
be fairly generic. The only sidecase I can see is that operator.
itself would not be looked up through operator. .

I read that there was previous debate on the subject, but I haven''t
been able to find why it was rejected.

I sent this message to the Boost mailing list, in error, they referred
me to Usenet.



我知道有两个理由反对它,第一个原因是

标准委员会的普遍共识是它可能

引入太多麻烦*,因为如果用户使用.-运算符,用户永远不会知道会发生什么?b

提到了如何实现正常行为。我知道没有

令人信服的理由允许它,因为它确实无法实现无法用其他方式模拟的行为。

*事实上最近的一项提案(n2200)建议所有运营商,除了以外的
。 (成员选择),::(名称空间)和。*(成员指针),

应该可以作为成员和非成员(包括

new和delete)重载。


-

Erik Wikstr?m

There are two reasons against it that I know of, the first being that
the general consensus in the standard committee is that it might
introduce too much trouble* , since a user would never know what will
happen if he uses the .-operator, the second is the problem you
mentioned about how to implement the normal behaviour. I know of no
convincing reason for allowing it since it really would not enable
behaviour that can''t be simulated in other ways.

* In fact a recent proposal (n2200) suggests that all operators,
except . (member selection), :: (namespace) and .* (memberpointer),
should be overloadable both as members and non member (that includes
new and delete).

--
Erik Wikstr?m


On 14 mei,08 :12,Erik Wikstr?m< eri ... @ student.chalmers.sewrote:
On 14 mei, 08:12, Erik Wikstr?m <eri...@student.chalmers.sewrote:

我知道有两个理由反对它,第一个是

标准委员会的普遍共识是,它可能会引入太多麻烦*因为用户永远不会知道会是什么会产生什么?b $ b如果他使用.-运算符会发生,第二个是你提到的关于如何实现正常行为的问题。我知道没有

令人信服的理由允许它,因为它真的不会启用

的行为,这是不能用其他方式模拟的。
There are two reasons against it that I know of, the first being that
the general consensus in the standard committee is that it might
introduce too much trouble* , since a user would never know what will
happen if he uses the .-operator, the second is the problem you
mentioned about how to implement the normal behaviour. I know of no
convincing reason for allowing it since it really would not enable
behaviour that can''t be simulated in other ways.



我特别想到了一些事情,主要是允许

透明转发接口。给定可变参数模板和

可重载运算符。你可以这样定义一个函数:


模板< typename R,typename ... Argtypes>

auto operator。(std :: string funcname, Argtypes ... args){return

memfun(this,new gen_send< R,ArgTypes ...>(funcname);}

template< typename R, typename ... Argtypes>

class gen_send {

private:

string funcname;

public:

R& operator()(Argtypes ...参数){

//序列化并发送

//等待返回值,返回值

}

};


允许透明转发名为的函数,

无关紧要它的功能是什么。编组返回类型可能会导致一两个小麻烦,但我认为这是一个相当简单的方法。

I was thinking of a few things in particular, mainly allowing
transparent forwarding of interfaces. Given variadic templates and an
overloadable operator. you could define a function as such:

template <typename R, typename... Argtypes>
auto operator.(std::string funcname, Argtypes... args) { return
memfun(this, new gen_send<R, ArgTypes...>(funcname); }
template <typename R, typename... Argtypes>
class gen_send {
private:
string funcname;
public:
R &operator()(Argtypes... arguments) {
// serialize and send
// wait for return value, return value
}
};

that would allow transparently forwarding of the function called,
irrelevant of which function it was. Marshalling the return type might
cause one or two small bits of trouble but I think there''s a fairly
easy way around that.


*事实上最近的提案(n2200)表明所有运营商,除了。(bl)之外的
。 ection,::(namespace)和。*(memberpointer),

应该是成员和非成员都可以重载(包括

new和delete)。
* In fact a recent proposal (n2200) suggests that all operators,
except . (member selection), :: (namespace) and .* (memberpointer),
should be overloadable both as members and non member (that includes
new and delete).



这不会给typeid特别是sizeof造成麻烦吗?

Wouldn''t that cause trouble with typeid and especially sizeof?


5月14,8:12 am,Eri​​k Wikstr?m< eri ... @ student.chalmers.sewrote:
On May 14, 8:12 am, Erik Wikstr?m <eri...@student.chalmers.sewrote:

On 14 Maj,07:36," dasca ... @ gmail.com" < dasca ... @ gmail.comwrote:
On 14 Maj, 07:36, "dasca...@gmail.com" <dasca...@gmail.comwrote:


我想知道,为什么重载运算符。 (期间)被禁止?它可以让一些奇怪的应用程序成为可能(动态继承和

透明的远程方法调用在我脑海中浮现)并且它会相当于

通用的。我能看到的唯一侧面是那个操作符。

本身不会通过运算符查找。 。
I was wondering, why is overloading operator. (period) forbidden? It
would make a few odd applications possible (dynamic inheritance and
transparent remote method invocation spring to my mind) and it would
be fairly generic. The only sidecase I can see is that operator.
itself would not be looked up through operator. .


我读到之前有关于这个主题的辩论,但我没有

能够找到被拒绝的原因。
I read that there was previous debate on the subject, but I haven''t
been able to find why it was rejected.


我知道有两个理由反对它,第一个是

普遍共识在标准委员会中,它可能会引入太多麻烦*,因为如果用户使用。-operator,$ b $,用户永远不会知道会发生什么? b
There are two reasons against it that I know of, the first being that
the general consensus in the standard committee is that it might
introduce too much trouble* , since a user would never know what will
happen if he uses the .-operator,



按照这个标准,你不能超载任何操作符。

By that standard, you couldn''t overload any of the operators.


第二个是你的问题

提到了如何实现正常行为。
the second is the problem you
mentioned about how to implement the normal behaviour.



答案也是众所周知的:(& obj) - > ;.

The answer to that is also well known: (&obj)->.


我知道没有

令人信服的理由允许它,因为它真的不会启用

的行为,这是不能用其他方式模拟的。
I know of no
convincing reason for allowing it since it really would not enable
behaviour that can''t be simulated in other ways.



智能参考和代理。

Smart references and proxies.


*事实上最近的提案(n2200)表明所有运算符,

除外。 (成员选择),::(名称空间)和。*(成员指针),

应该可以作为成员和非成员(包括

new和delete)重载。
* In fact a recent proposal (n2200) suggests that all operators,
except . (member selection), :: (namespace) and .* (memberpointer),
should be overloadable both as members and non member (that includes
new and delete).



嗯。我必须要看一下,但如果

他们允许赋值操作员成为非成员,我会非常惊讶。那个

会导致问题无止境。 (我也很好奇地问候

到?:。我不认为我想看到它超载,除非

有要求第一个参数是用户

定义的类型。)


-

James Kanze(GABI软件)电子邮件:ja * ********@gmail.com

Conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9placeSémard, 78210 St.-Cyr-l''coco,法国,+ 33(0)1 30 23 00 34

Hmmm. I''ll have to look at it, but I''d be very surprised if
they allow the assignment operator to be a non-member. That
would cause no end of problems. (I''m also curious with regards
to ?:. I don''t think I''d like to see it overloadable unless
there was a requirement that the first argument be a user
defined type.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


这篇关于为什么重载运算符。 (会员运营商)被禁止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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