我有一个与运算符重载有关的问题,定义一个类及其运算符重载函数很容易,如下代码所示:
typedef std::vector<std::vector<int> > ARRAY;
class ABC
{
public:
ABC():a(0)
{
};
int a;
ABC& operator = (int value)
{
a = value;
return *this;
}
ABC(int value)
{
a = value;
}
};
void obtain_priority_array(const std::vector<double> &weighting, const ABC &priority_array=NULL)
{
}
int main()
{
vector<double> weighting;
weighting.push_back(0.8);
weighting.push_back(0.9);
weighting.push_back(0.6);
weighting.push_back(0.3);
weighting.push_back(0.5);
ABC test;
obtain_priority_array(weighting, test);
return 0;
}
在上面的例子中,class ABC
重新定义operator =
了函数 void obtain_priority_array(const std::vector<double> &weighting, const ABC &priority_array=NULL)
可以有一个默认参数const ABC &priority_array=NULL
。我的问题是如果函数中的最后一个参数来自STL,例如,const std::vector<int> &priority_array=NULL
我们如何重新定义operator =
. 谢谢!
编辑:
void gain_priority_array(const std::vector &weighting, const std::vector<int> &sample=NULL
)失败!