zoukankan      html  css  js  c++  java
  • 关于c++中public & private方法调用问题

    class IDNoIdentifier
    {
    public:
        IDNoIdentifier();
        ~IDNoIdentifier();
    
        typedef vector<cv::Rect> CvRectVectorType;
    
        bool Init();
        bool Cleanup();
        bool HandleData(const Mat& rawImg,string& sNoInfo,string& sError);
    
    private:
        bool IDNoLocation(const Mat& rawImg,        //输入原始BGR24数据
            Mat& dstImg,                            //经偏转校正等处理后的结果图,BGR8(灰度图),该函数内创建内存
            CvRectVectorType& IDNoVector,            //基于灰度图的字符位置序列
            string& sError);                        //如果处理失败,返回失败原因
    
        bool IDNoIdentify(const Mat& dstImg,const CvRectVectorType& IDNoVector,string& sInfo,string& sError);
    
    private:
    };
    bool IDNoIdentifier::HandleData( const Mat& rawImg,string& sNoInfo,string& sError)
    {
        if (rawImg.empty())
        {
            return false;
        }
        Mat dstImg;
        CvRectVectorType posionVec; 
        if (!IDNoLocation(rawImg,dstImg,posionVec,sError))
        {
            if (!dstImg.empty())
            {
                dstImg.release();
            }
            return false;
        }
    
    ....
    }

    public类型的HandleData里面包括了一个private的IDNoLocation

    class codeExtract
    {
    public:
        codeExtract();
        ~codeExtract();
    private:
        
        Mat picProcess(Mat img);
    }
    bool IDNoIdentifier::IDNoLocation( const Mat& rawImg,Mat& dstImg,CvRectVectorType& IDNoVector,string& sError)
    {
        
        codeExtract code;
        
        /*图片二值化*/
        Mat img=code.picProcess(rawImg);   //字符清楚,矫正角度
    ...
    }

    会报错, error C2248: “codeExtract::picProcess”: 无法访问 private 成员(在“codeExtract”类中声明)

    原因:因为这是IDNoIdentifier类下的方法啊。在这个类下不能看到类codeExtract中定义的私有方法滴

  • 相关阅读:
    Path Sum
    Intersection of Two Linked Lists (求两个单链表的相交结点)
    Nginx入门资料
    赛马问题
    翻转单词顺序 VS 左旋转字符串
    重建二叉树
    Fibonacci相关问题
    Find Minimum in Rotated Sorted Array(旋转数组的最小数字)
    常用查找算法总结
    Contains Duplicate
  • 原文地址:https://www.cnblogs.com/Daringoo/p/4495341.html
Copyright © 2011-2022 走看看