读书人

operator unsigned() 与 unsigned ope

发布时间: 2012-11-05 09:35:12 作者: rapoo

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();

读书人网 >C++

热点推荐