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

  • 相关阅读:
    C++ XML文件解析
    coco2d-x create tableView
    cocos2d-x button setTitleLabel
    cocos2d-X create std colorlayer
    Windows cmd "tree"
    C/C++ std::function && std::bind
    C/C++ “std::invoke”: 未找到匹配的重载函数
    31 迭代器 Iterator 是什么?
    30 哪些集合类是线程安全的?
    02 rpx 与 px
  • 原文地址:https://www.cnblogs.com/wenrenhua08/p/3995313.html
Copyright © 2011-2022 走看看