zoukankan      html  css  js  c++  java
  • C++ 类型转换操作与操作符重载 operator type() 与 type operator()

      类型转换操作符(type conversion operator)是一种特殊的类成员函数,它定义将类类型值转变为其他类型值的转
    换。转换操作符在类定义体内声明,在保留字 operator 之后跟着转换的目标类型。
    class CVImage
    {
    public :
        CVImage();
        explicit CVImage(unsigned int width, unsigned int height, unsigned short depth, unsigned short nChannels = 3);
        CVImage(CVImage& img);
        ~CVImage();

        void ReleaseImage();
        int Resize(unsigned int width, unsigned int height, unsigned short depth, unsigned short nChannels = 3);
        
        operator IplImage*() { return m_image; };
        inline IplImage* GetImage() { return m_image; };

    private:
        IplImage* m_image;
    };
    先来说下类型转换构造函数:C++中的explicit用来修饰类的构造函数,表明该构造函数是显示的,在调用有参数的构造函数
    时需要显式调用:
        CVImage cImg = CVImage(640, 480, 8, 1);
        
        运算符重载操作:
        IplImage* operator() ()
        {
            return m_image;
        }

  • 相关阅读:
    枚举子集 Codeforces306 Div2 B
    UVA140 剪枝
    回溯法浅谈
    UVA10976
    UVA11059
    BZOJ3355
    hdu 2509 博弈 *
    博弈专题
    hdu 1404 找sg ***
    hdu 4759 大数+找规律 ***
  • 原文地址:https://www.cnblogs.com/wenrenhua08/p/3995313.html
Copyright © 2011-2022 走看看