这几句话是运算符重载吗?求高手看看
本帖最后由 chenxue1111 于 2013-05-03 20:47:24 编辑
Mat operator()( Range rowRange, Range colRange ) const;
Mat operator()( const Rect& roi ) const;
Mat operator()( const Range* ranges ) const;
//! converts header to CvMat; no data is copied
operator CvMat() const;
//! converts header to CvMatND; no data is copied
operator CvMatND() const;
//! converts header to IplImage; no data is copied
operator IplImage() const;
#include <iostream>
class A{
public:
int operator()(int x, int y){
return x + y;
}
};
int main(){
A sum;
std::cout<<sum(1, 2)<<std::endl;//效果跟函数int sum(int, int)一样。。
return 0;
}
#include <iostream>
using namespace std;
class A{
public:
A(int x = 0): val(x){}
operator int(){ //可以将类A的对象转化为int, 转化的时候会调用这个函数。。
cout<<"operator int"<<endl;
return val;
}
private:
int val;
};
void fun(int x){
cout<<x<<endl;
}
int main(){
A a(1);
fun(a);//可以在需要int类型的地方使用类A的对象。。
return 0;
}