简体   繁体   English

重载成员选择运算符

[英]overload member selection operator

is there any way to overload the "dot"-operator "." 有什么办法可以重载“点”-“运算符”。

We would like to use our old code base while rewriting the ORM layer. 我们想在重写ORM层时使用我们的旧代码库。 So we had the idea to wrap the objects and add some new semantic to the member selection operator "." 因此,我们想到了包装对象并向成员选择运算符“”添加一些新语义的想法。

We found a several sites discussing that, including here on SO, all say in theory it would be fine but current C++ standard does not allow it. 我们找到了几个讨论该问题的站点,包括SO在内,从理论上讲都可以,但是当前的C ++标准不允许。

Maybe there is already a compiler which does it? 也许已经有一个编译器了?

EDIT 编辑

thanks for your quick answers; 感谢您的快速回答; We see it might be hard if not impossible to find such a compiler. 我们看到找到这种编译器可能很困难,即使不是没有可能。 Any further hints are appreciated. 任何进一步的提示表示赞赏。 All your posted resources we already had read... 您已经阅读的所有发布资源...

Briefly what we want to achieve: The wrapper does not have any own members, it just should provide the former real object in another way. 简而言之,我们要实现的目标:包装器没有任何自己的成员,它应该以另一种方式提供以前的真实对象。 It would be very convenient to implement our new layer for reasons of backward compatibility - we could avoid to modify the legacy client code in about >4000 occurrences. 出于向后兼容的原因,实现我们的新层将非常方便-我们可以避免在大约4000次以上的情况下修改旧版客户端代码。

If you have any other idea how to proceed in another way, please tell. 如果您有其他想法如何以其他方式进行,请告诉。 Will this limit be still there in C++11 ? 在C ++ 11中此限制还会存在吗?

EDIT 2 编辑2

Not sure yet, I am going to report what we do. 不确定,我将报告我们的工作。

You can't overload the dot operator, and there is no c++ compiler that supports this property. 您不能重载点运算符,并且没有支持此属性的c ++编译器。 Check this link from wikipedia which explains operator overloading in C++ in more detail. 检查来自Wikipedia的此链接,该链接更详细地说明了C ++中的运算符重载。 http://en.wikipedia.org/wiki/C%2B%2B_operators http://en.wikipedia.org/wiki/C%2B%2B_operators

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM