错误LNK2001:解析外部符号市民:静态类[复制](error LNK2001: unresolv

2019-10-20 10:31发布

这个问题已经在这里有一个答案:

  • 什么是未定义参考/解析的外部符号错误,我该如何解决? 32个回答

我想不通为什么我recieving这个错误。 任何人都可以伸出援助之手。 我需要声明VideoCapture捕获在头文件并调用它在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; 
   }
  }
}

任何帮助将不胜感激

Answer 1:

在定义一个类, static变量是一个纯粹的声明 。 您只宣称capture某处存在。

您需要添加的定义 。 把这些变量存在。

在C的任何版本++

您可以分别定义在你的CPP文件中的变量。

const VideoCapture Video::capture;

在C ++ 17或更高

你可以声明变量inline在你的头,使之成为定义。

static inline VideoCapture capture;


文章来源: error LNK2001: unresolved external symbol public: static class [duplicate]