哪些是可以重载的运算符? [英] which are the operators that can be overloaded ??

查看:78
本文介绍了哪些是可以重载的运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i不知道以下答案。


现在,你可以超载所有基本确定的运营商

运行时(像sizeof()这样的运算符的coz''不能超载。

现在我的疑问是,如果你有类似的东西

p-> a ....其中p(说)是用户定义类型的指针,那么你可以重载这个因为p是在运行时确定的???这是对的吗? ??

如果a也是是一个用户定义的类的对象,


然后是(& a)。成员有效?????我认为所有的。不能超载

....为什么???? (即使在这种情况下)

hi
i wasnt to know the answer for the following.

now ,u can overload all the operators which are basically determined at
runtime (coz'' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like

p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined at runtime ???is this right ???
also if "a" is an object of the some user defined class,

then is (&a).member valid ?????I thought all "." cannot be overloaded
....why ???? (even in such cases)

推荐答案

maadhuu写道:
maadhuu wrote:
我不知道以下答案。现在我的疑问是,如果你有像

p-> a ....其中p(说)是用户定义类型的指针,然后你可以重载这个,因为p是在运行时决定的???这是正确的吗 ???


编号如果''p''是一个指针(对任何东西),它是一个内置类型。为它

运营商喜欢* - > + - + = - = = ==!=是预定义的,不能是
重载。

如果是a是一个用户定义的类的对象,
然后是(& a)。成员有效?????我认为所有。不能超载
...为什么???? (即使在这种情况下)
i wasnt to know the answer for the following.

now ,u can overload all the operators which are basically determined at
runtime (coz'' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like

p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined at runtime ???is this right ???
No. If ''p'' is a pointer (to anything), it''s a built-in type. For it
operators like * -> + - += -= = == != are predefined and cannot be
overloaded.
also if "a" is an object of the some user defined class,

then is (&a).member valid ?????I thought all "." cannot be overloaded
...why ???? (even in such cases)




如果''a''属于某些UDT,则该UDT可以具有运算符&重载,并且

返回一个其他类型的对象,其中使用了点(。)运算符

。如果你重载

运算符& ;,那么获取该对象的地址并不容易,但你可能不需要获取地址。


V



If ''a'' is of some UDT, then that UDT can have operator & overloaded, and
returning an object of some other type for which the dot (.) operator is
used. It''s not easy to get the address of that object if you overload the
operator&, but you may not need to have the address taken.

V


Victor Bazarov写道:
Victor Bazarov wrote:
maadhuu写道:
maadhuu wrote:
我不知道答案对于以下内容。

现在,你可以重载基本上在运行时确定的所有运算符(像sizeof()这样的运算符的coz''不能重载。
现在我的疑问是,如果你有像

p-> a ....其中p(说)是用户定义类型的指针,那么你可以
重载这个因为p是在运行时确定的???这是对的吗?

如果''p''是一个指针(对任何东西),它是一个内置类型。为它
运营商,如* - > + - + = - = = ==!=是预定义的,不能超载。
i wasnt to know the answer for the following.

now ,u can overload all the operators which are basically determined at
runtime (coz'' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like

p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined at runtime ???is this right ???

No. If ''p'' is a pointer (to anything), it''s a built-in type. For it
operators like * -> + - += -= = == != are predefined and cannot be
overloaded.




你在说什么?!?


内置用户定义类的指针如何?



What are you talking about?!?

How is a pointer to a user defined class built-in?

如果a是是一个用户定义的类的对象,
然后是(& a)。成员有效?????我认为所有。不能超载
...为什么???? (即使在这种情况下)
also if "a" is an object of the some user defined class,

then is (&a).member valid ?????I thought all "." cannot be overloaded
...why ???? (even in such cases)



如果你超载。你将如何访问班级成员?

如果某个UDT属于某个UDT,那么该UDT可以拥有运营商&重载,并返回使用点(。)运算符的其他类型的对象。如果你重载
操作符& ;,那么获取该对象的地址并不容易,但你可能不需要获取地址。

V


if u overload . how will you access class members?


If ''a'' is of some UDT, then that UDT can have operator & overloaded, and
returning an object of some other type for which the dot (.) operator is
used. It''s not easy to get the address of that object if you overload the
operator&, but you may not need to have the address taken.

V




我建议你查看由Bruce Eckel撰写的关于C ++的优秀参考书:


思考C ++第1版和第2版:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html


关于运算符重载,Valume One中有一整章。


唯一不能超载的运算符是。和。*



I suggest you check out the excellent reference book on C++ by Bruce Eckel:

Thinking in C++ Vols 1 and 2:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

There is an entire chapter in Valume One on operator overloading.

the only operators you can''t overload are . and .*


Aaron Gage写道:
Aaron Gage wrote:
Victor Bazarov写道:
Victor Bazarov wrote:
maadhuu写道:

maadhuu wrote:

我不知道以下答案。
现在,你可以重载所有基本确定的操作员
运行时(像sizeof()这样的运算符的coz''不能重载。
现在我的疑问是,如果你有像

p-> a ....其中p (比方说)是一个用户定义类型的指针,然后你可以重载这个,因为p是在运行时确定的???这是对吗???

没有如果''p''是一个指针(对任何东西),它就是一个内置类型。为它
运营商,如* - > + - + = - = = ==!=是预定义的,不能重载。
i wasnt to know the answer for the following.

now ,u can overload all the operators which are basically determined at
runtime (coz'' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like

p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined at runtime ???is this right ???

No. If ''p'' is a pointer (to anything), it''s a built-in type. For it
operators like * -> + - += -= = == != are predefined and cannot be
overloaded.



你在说什么?!?


What are you talking about?!?




C ++。你在说什么?

内置用户定义类的指针怎么样?



C++. What are YOU talking about?
How is a pointer to a user defined class built-in?




它是一个指针。指针是一种内置类型。


好​​的,让我们不要争论这个。继续尝试重载操作符+

作为指针。我敢于你!



It''s a pointer. A pointer is a built-in type.

OK, let''s not argue about this. Go ahead and try to overload operator+
for your pointer. I DARE YOU!

如果是a,是一个用户定义的类的对象,
然后是(& a)。成员有效?????我认为所有。不能超载
...为什么???? (即使在这种情况下)
also if "a" is an object of the some user defined class,

then is (&a).member valid ?????I thought all "." cannot be overloaded
...why ???? (even in such cases)



如果你超载。你将如何访问班级成员?


if u overload . how will you access class members?


如果''a''属于某些UDT,那么该UDT可以拥有运营商&重载,并返回使用点(。)运算符的其他类型的对象。如果你重载
操作符& ;,那么获取该对象的地址并不容易,但你可能不需要获取地址。

V

If ''a'' is of some UDT, then that UDT can have operator & overloaded, and
returning an object of some other type for which the dot (.) operator is
used. It''s not easy to get the address of that object if you overload the
operator&, but you may not need to have the address taken.

V



我建议你看看Bruce Eckel关于C ++的优秀参考书:

用C ++ 1和2思考:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

在Valume One中有一整章关于操作符重载。

唯一不能超载的操作符是。和。*


I suggest you check out the excellent reference book on C++ by Bruce Eckel:

Thinking in C++ Vols 1 and 2:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

There is an entire chapter in Valume One on operator overloading.

the only operators you can''t overload are . and .*




谢谢。 :-)


我建议你自己阅读。还有其他书籍。并且下次注意




V



Thanks. :-)

I suggest you read it yourself. And other books too. And pay attention
next time.

V


这篇关于哪些是可以重载的运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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