[求助] VS2010编译报错:重定义
交代下背景:环境:VS2010 旗舰
项目名:Output02
头文件:Processor.h
源文件:main.cpp
CaptureImage.cpp
ProcessImage.cpp
MouseControl.cpp
为了查找编译报错原因,我把main.cpp写的很简单:
程序代码:
#include "Processor.h" int main() { return 0; }
下面贴上Processor.h:
程序代码:
#ifndef _PROCESSOR #define _PROCESSOR #include <windows.h> #include <WinUser.h> #include <cv.h> #include <highgui.h> class CaptureImage { private: CvCapture* camCapture; IplImage* frameImg; int* pFinishIndex; char dir[30]; char fileName[30]; int fileNameCounter; int camW,camH; int gap; int deviceNo; protected: public: CaptureImage(int gap,int* pFinishIndex); CaptureImage(int gap,int deviceNo,int* pFinishIndex); //ParamList: int gap,int DeviceNo. bool Init(); bool Capture(); void Release(); inline int GetGap() {return gap;} inline CvCapture** GetCamCapture() {return &camCapture;} inline IplImage** GetFrameImg() {return &frameImg;} inline int GetFileNameCounter() {return fileNameCounter;} inline char* GetDir() {return dir;} inline int GetCamW() {return camW;} inline int GetCamH() {return camH;} }; class ProcessImage { private: IplImage *img1,*img2,*imgRes; int *pCpFinishIndex; char dirCapFormat[30]; char dirResFormat[30]; char fileName[30]; int lastIndex; bool processFlag; bool isNew; bool IsTargetDot(IplImage*,IplImage*,int,int); bool IsValidSurround(IplImage*,IplImage*,int,int); bool IsTargetDot(IplImage*,int,int); CvRect TargetRegion(IplImage*); bool FileExists(char*); void Release(); protected: public: ProcessImage(int *pCpFinishIndex); bool Init(int camW,int camH); bool Processor(int imgIndex1,int imgIndex2); void SetProcessFlag(bool processFlag); inline int GetLastIndex(){return lastIndex;} }; class MouseController { private: static INPUT Input; static double screenWidth; static double screenHeight; protected: public: MouseController(); static void Move(int x,int y); static void MoveRelated(int relatedX,int relatedY); static void LeftClick(); static void LeftPress(); static void LeftRelease(); static void RightClick(); static void RightPress(); static void RightRelease(); }; INPUT MouseController::Input = *new INPUT(); double MouseController::screenWidth = ::GetSystemMetrics(SM_CXSCREEN); double MouseController::screenHeight = ::GetSystemMetrics(SM_CYSCREEN); unsigned __stdcall CaptureImageRun(void*); unsigned __stdcall ProcessImageRun(void*); #endif
之后编译报错信息为:
1>MouseControl.obj : error LNK2005: "private: static double MouseController::screenWidth" (?screenWidth@MouseController@@0NA) 已经在 main.obj 中定义
1>MouseControl.obj : error LNK2005: "private: static struct tagINPUT MouseController::Input" (?Input@MouseController@@0UtagINPUT@@A) 已经在 main.obj 中定义
1>MouseControl.obj : error LNK2005: "private: static double MouseController::screenHeight" (?screenHeight@MouseController@@0NA) 已经在 main.obj 中定义
1>E:\VS2010 WorkSpace\Output02\Debug\Output02.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
哪位大侠能看一下问题出在哪里?
小弟不太懂头文件引入时编译的机制
PS:上面头文件中的声明实现部分在其他三个cpp文件中,这个会不会影响呢?
[ 本帖最后由 nandiin 于 2013-3-18 19:20 编辑 ]