重载运算符函数的问题
一个重载运算符函数不能带有缺省参数是什么意思
下面是一个类型转换函数
operator double()
{
cout<<"Type changed....\n";
return double(real);
}
这是string类对象的赋值
string&string::operator=(const string string &s)
{}
联想数组的运算符重载
long &Assc_array::operator[](char *nm)
{}
[解决办法]
operator double()
{
cout < <"Type changed....\n";
return double(real);
}
“operator double()”是类型转换函数:将类的对象转换为标准的数据类型double型,规定无参数。
这是string类对象的赋值
string&string::operator=(const string string &s)
{}
“operator=(const string string &s”是运算符重载函数,可以看出,“operator=”是类的成员函数。c++中规定,类的成员函数作为运算符重载函数时,一般隐藏一个参数。当类的友元函数作为运算符重载函数时,当运算符是二目运算符时,进行函数调用时,一般情况下传递两个参数(不隐藏参数)。
最后一个我也不清楚,不好意思了。