变量不在派生类中存储数据

时间:2013-03-08 21:47:09

标签: inheritance opencv

class A
{
public:
    virtual ~A() {}

    virtual Process(cv::Mat& img) {}
} ;

class B : public A
{
public:

     Process(cv::Mat& inputimage)
     {

        if (img.empty())
        {
            img = inputimage.clone();
            return;
        }

       else
           cv::imshow ("image", img);
    }
private:

       cv::Mat img;

  };

遇到这种情况时,这个img总是空的。 我在我的主要代码中使用此代码的方式是:

PSEUDO CODE

int main ()`
{
   A* a;

   a = new B;

   while(avi.notempty()
   {
       a.Process(nextFrame);
   }
}

代码不完整但基本上问题是变量没有以某种方式存储。

1 个答案:

答案 0 :(得分:0)

当我改变

时,问题就解决了

img.copyTo(img2);

img2 = img.clone();

谢谢!