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;
        }

  • 相关阅读:
    7. 初识Python之函数
    6. 初识Python之dict和set
    5. 初识Python之循环语句
    4. 初识Python之条件语句
    3. 初识Python之列表
    原生js实现一个小小的轮波
    原生js实现弹幕
    js实现一个简单的学生管理系统
    js绘制时钟
    js实现的学生管理系统
  • 原文地址:https://www.cnblogs.com/wenrenhua08/p/3995313.html
Copyright © 2011-2022 走看看