开发者

Strange error when trying to declare enum in C++ Visual Studio 2010

开发者 https://www.devze.com 2023-03-30 18:48 出处:网络
I\'m having a strange issue compiling and old C++ Visual Studio开发者_开发百科 5 project in Visual Studio 2010.There is a nagging compiler error I cannot get rid of that appears to be related to the e

I'm having a strange issue compiling and old C++ Visual Studio开发者_开发百科 5 project in Visual Studio 2010. There is a nagging compiler error I cannot get rid of that appears to be related to the enumeration "DBTYPE". A snippit of the .h file is given below with a few extra lines incase the error is coming from above:

struct CBrowseField;
class CODBCBrowseDlg;

typedef CArray <CBrowseField*, CBrowseField*&> FLDNAMES;
typedef CArray <CString, LPCTSTR > COLNAMES;

enum DBTYPE
{                 //this bracket is where all 7 errors point to.
   DB_FOXPRO26,
   DB_OTHERS
};

I get 7 errors when I compile, all saying the same thing and all pointing to the same line number. The error is as follows:

Error 71 error C2371: 'DBTYPE' : redefinition; different basic types d:\temp\npc\print manager - 1\core\blib\odbcbrowsegrid.h 29 1 npcnt

So what the heck is going on here. I've checked and rechecked the syntax. It looks fine to me. I've word searched the entire directory to see if there is another instance of DBTYPE and there isn't. What am I missing? If its really being redefined, why the heck doesn't it tell me where the other definitions are?


Looks like you are including, probably indirectly, the odbcbrowsegrid.h file, and it happens to contain something with the same name, I'd bet in line 29.

So you'll just have to call your enum differently.

AFTERTHOUGHT: Unless... your file is actually odbcbrowsegrid.h. Then I've said a nonsense.


Are you using OleDb somewhere? (or something that includes its headers) It defines a DBTYPE type (in oledb.h). That could cause a conflict.


To get that particular error, you need to do something like:

typedef int DBTYPE;
enum DBTYPE {DB_FOXPRO26, DB_OTHERS};

(Defining DBTYPE as an enum twice gives a different error). Which means that while the include guards (#define ODBCBROWSERGRID_H etc) are a good idea, they aren't going to solve this problem.

Basically, you are using an include file which uses the name DBTYPE for some other purpose. You could track down the include file, figure out whether or not you actually need that other file, and then, if not, figure out how to avoid loading it ---- or you could just give your DBTYPE a different name. (recommended)

0

精彩评论

暂无评论...
验证码 换一张
取 消