在一个类(CMyListCtrl)中使用ADO访问数据库。该类的头文件的前几行是这样的:
#import "e:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")#include <ole2.h>
#include <stdio.h>
#include <conio.h>编译有7个错误。如下:
ylistctrl.cpp
i:\projects\coaddress\debug\msado15.tlh(171) : error C2011: 'LockTypeEnum' : 'enum' type redefinition
i:\projects\coaddress\debug\msado15.tlh(214) : error C2011: 'DataTypeEnum' : 'enum' type redefinition
i:\projects\coaddress\debug\msado15.tlh(258) : error C2011: 'FieldAttributeEnum' : 'enum' type redefinition
i:\projects\coaddress\debug\msado15.tlh(279) : error C2011: 'EditModeEnum' : 'enum' type redefinition
i:\projects\coaddress\debug\msado15.tlh(287) : error C2011: 'RecordStatusEnum' : 'enum' type redefinition
i:\projects\coaddress\debug\msado15.tlh(530) : error C2011: 'ParameterDirectionEnum' : 'enum' type redefinition
I:\Projects\CoAddress\Mylistctrl.cpp(676) : error C2065: 'adLockOptimistic' : undeclared identifier
Error executing cl.exe.都是在一个叫msado15.tlh的文件中的错误,而且都是c2011错误~~~~
我在另外一个程序中也使用了这个类,没有出现这些问题。(这个类原来是在那个程序中进行设计的,由于某些原因需要移到当前的程序中使用)
个位大虾~有谁碰过这个问题!谢谢谢谢~~~~~~~~~

解决方案 »

  1.   

    如果redefinition的是一样的,那么把这个注释掉不就行了:P
    要么找找看还有在哪里定义了这些类型。
      

  2.   

    原因是这样的,你在使用应用程序向导的时候选中了“数据库支持”选项。
    于是你的StdAfx.h中就有了如下两行:
    #include <afxdb.h> // MFC ODBC database classes
    #include <afxdao.h> // MFC DAO database     诸如 LockTypeEnum 等在以上文件中有定义,而在Import来的msado15.tlh文件中又对 LockTypeEnum 作了定义,那么当然会出现 redefinition了。解决方法:
        删除在stdafx.h中的那两行。
      

  3.   

    我的建议是,如果每次包含文件的时候最好用一下条件宏#ifndef  ****
     #include ****
     #import ***
     #...
    #endif这样这样的问题就会不出现了,特别是自己写的头文件。
      

  4.   

    看过你的问题了,首先表面上的错误是没有加入续行标志:
    #import "e:\Program Files\Common Files\System\ADO\msado15.dll"  \ no_namespace rename("EOF", "EndOfFile")#include <ole2.h>
    #include <stdio.h>
    #include <conio.h>
      

  5.   

    sdzym(石头),谢谢,成功了~没有错误了。