首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

operator unsigned() 与 unsigned operator ()();差别

2012-11-05 
operator unsigned() 与 unsigned operator ()()区别最近在看一个随机数产生类,是OpenCV里的RNG类,里面有

operator unsigned() 与 unsigned operator ()();区别
最近在看一个随机数产生类,是OpenCV里的RNG类,里面有些操作符重载,不太懂,求各位大哥帮忙理解。RNG类定义代码如下:

C/C++ code
class CV_EXPORTS RNG{public:    enum { UNIFORM=0, NORMAL=1 };    RNG();    RNG(uint64 state);    //! updates the state and returns the next 32-bit unsigned integer random number    unsigned next();    operator uchar();    operator schar();    operator ushort();    operator short();    operator unsigned();    //! returns a random integer sampled uniformly from [0, N).    unsigned operator ()(unsigned N);    unsigned operator ()();    operator int();    operator float();    operator double();    //! returns uniformly distributed integer random number from [a,b) range    int uniform(int a, int b);    //! returns uniformly distributed floating-point random number from [a,b) range    float uniform(float a, float b);    //! returns uniformly distributed double-precision floating-point random number from [a,b) range    double uniform(double a, double b);    void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange=false );    //! returns Gaussian random variate with mean zero.    double gaussian(double sigma);    uint64 state;};

operator unsigned() 与 unsigned operator ()();有什么区别呢?其他的那几个重载函数都怎样理解呢?
告诉我吧,谢谢谢谢啦!!!

[解决办法]
2.unsigned operator ()();
-----------------
这个应该是重载()操作符吧
[解决办法]
operator()()例子:
C/C++ code
template<class F>class A{ unsigned int m_XXX; A(F func){  m_XXX=F(); }};void main(){ RNG r; A<RNG> a(r);}
[解决办法]
RNG png; 
1. 用户自定义的转换函数

float f = png;
2. 重载函数调用运算符()
png();

热点排行