请说明以下功能 [英] Please explain the following function
本文介绍了请说明以下功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个以以下内容开头的函数定义:
整数运算符*(向量&y)
{
身体
}
在运算符后加*并在括号前打开此函数的含义是什么?
I have come across a function definition starting as:
int operator*(vector &y)
{
body
}
After putting * just after operator and before opening brace of argument what this function means?
推荐答案
我是 ^ ]
这是C ++提供的一项功能,称为运算符重载.如果在类对象的上下文中使用了运算符,则可以使用它来更改其含义.
看看下面的代码.
This is a feature provided by the C++ called operator overloading . Using this you can change the meaning of operator if it is used in context of your class object.
Have a look at the following code.
Class YourClass
{
public :
int operator*(vector &y)
{
body
}
};
main ()
{
vector v;
YourClass y;
y*v; ///Here operator* function will be called and v will be passed as a parameter
}
这篇关于请说明以下功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文