2014-07-08 74 views
1

我不明白爲什麼我收到此錯誤。任何人都可以伸出援助之手。 我需要聲明在頭文件VideoCapture採集和調用它Video.cpp錯誤LNK2001:無法解析的外部符號公共:靜態類

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; 
    } 
    } 
} 

任何幫助將是非常感謝

回答

8

這是一個聲明capture。它只是宣佈capture將存在某處

Video.h

static const VideoCapture capture; 

您需要添加定義。讓它存在。

Video.cpp

const VideoCapture Video::capture; 
+0

感謝您的答覆。哪裏可以添加VideoCapture Video :: capture的定義? – user3743939

+0

@ user3743939這就是我的答案。 :) –

相關問題