错误LNK2001:无法解析的外部符号public:静态类 [英] error LNK2001: unresolved external symbol public: static class
问题描述
我无法弄清楚为什么收到此错误.任何人都可以伸出援手. 我需要在头文件中声明VideoCapture Capture,并在Video.cpp中调用它
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;
}
}
}
任何帮助将不胜感激
推荐答案
在类定义中,static
变量仅是声明.您只声明了capture
将在某处存在.
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.
在任何版本的C ++中
您可以在cpp文件中单独定义变量.
You can separately define the variable in your cpp file.
const VideoCapture Video::capture;
在C ++ 17或更高版本中
您可以在标头中声明变量inline
以使其成为定义.
You can declare the variable inline
in your header to make it a definition.
static inline VideoCapture capture;
这篇关于错误LNK2001:无法解析的外部符号public:静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!