error LNK2001: unresolved external symbol public:

2019-08-01 15:52发布

I cannot figure out why i am recieving this error. Can anyone lend a hand. I need to declare VideoCapture capture in the header file and call it in Video.cpp

Video.h

class Video
{
    public:

    static VideoCapture capture;

    //Default constructor
    Video();

    //Declare a virtual destructor:
    virtual ~Video();

    //Method
    void Start();   

    private:
};

Video.cpp

#include "StdAfx.h"
#include "Video.h"
#include "UserInfo.h"
#include "Common.h"

void Video::Start()
{
  while(1)
  {
    Mat img;

    bool bSuccess = capture.read(img); // read a new frame from video

     if (!bSuccess) //if not success, break loop
    {
                    cout << "End of video" << endl;
                   break;
    }

    imshow("original video", img); //show the frame in "Original Video" window

    if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
   {
            cout << "esc key is pressed by user" << endl; 
            break; 
   }
  }
}

Any help would be greatly appreciated

1条回答
老娘就宠你
2楼-- · 2019-08-01 16:31

In a class definition, static variables are a merely a declaration. You have only declared that capture will exist somewhere.

You need to add the definition. Make the variable exist.

In any version of C++

You can separately define the variable in your cpp file.

const VideoCapture Video::capture;

In C++ 17 or later

You can declare the variable inline in your header to make it a definition.

static inline VideoCapture capture;
查看更多
登录 后发表回答