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

  • 相关阅读:
    事后诸葛亮
    冲刺总结
    Alpha第十天
    Alpha第八天
    Alpha第九天
    Alpha第六天
    Alpha第七天
    Alpha第五天
    Python之pytesseract模块-实现OCR
    Selenium4 IDE初体验
  • 原文地址:https://www.cnblogs.com/wenrenhua08/p/3995313.html
Copyright © 2011-2022 走看看