错误LNK2001:未解析的外部符号public:static class

use*_*939 1 c++ static-members linker-errors

我无法弄清楚为什么我收到这个错误.任何人都可以伸出援助之手.我需要在头文件中声明VideoCapture捕获并在Video.cpp中调用它

Video.h

class Video
{
    public:

    static VideoCapture capture;

    //Default constructor
    Video();

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

    //Method
    void Start();   

    private:
};
Run Code Online (Sandbox Code Playgroud)

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; 
   }
  }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激

Dre*_*ann 11

这是一个声明static.它只是宣称capture将存在于某个地方.

Video.h

const VideoCapture Video::capture;
Run Code Online (Sandbox Code Playgroud)

您需要添加定义.让它存在.

Video.cpp

static inline VideoCapture capture;
Run Code Online (Sandbox Code Playgroud)