我觉得很奇怪,我在stdafx.h文件中加了这句代码:
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF") 
接着我在CFormView的派生类中定义
// 定义ADO连接、命令、记录集变量指针
_ConnectionPtr m_pConnection;
_CommandPtr m_pCommand;
_RecordsetPtr m_pRecordset;
结果编译就出错。
syntax error : missing ';' before identifier 'm_pConnection'
e:\3\3\3view.h(42) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
e:\3\3\3view.h(42) : error C2501: 'm_pConnection' : missing storage-class or type specifiers
e:\3\3\3view.h(43) : error C2146: syntax error : missing ';' before identifier 'm_pCommand'
e:\3\3\3view.h(43) : error C2501: '_CommandPtr' : missing storage-class or type specifiers
e:\3\3\3view.h(43) : error C2501: 'm_pCommand' : missing storage-class or type specifiers
e:\3\3\3view.h(44) : error C2146: syntax error : missing ';' before identifier 'm_pRecordset'
e:\3\3\3view.h(44) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
e:\3\3\3view.h(44) : error C2501: 'm_pRecordset' : missing storage-class or type specifiers
Error executing cl.exe.3.exe - 9 error(s), 0 warning(s)
这是什么原因呢?

解决方案 »

  1.   

    我新建了一个mfc程序,什么功能都没写,把上述代码加进去就没问题,不知道为什么会这样
      

  2.   

    在定义这几个变量的时候,文件(.cpp或者.h)前面必须要include "stdafx.h".
      

  3.   

    #include "stdafx.h"
    ..........
    .........
    ...........
    _ConnectionPtr m_pConnection; 
    _CommandPtr m_pCommand; 
    _RecordsetPtr m_pRecordset; 
      

  4.   

    还是有问题啊,我在stdafx.h文件中加了这句代码: 
    #import "c:\program files\common files\system\ado\msado15.dll" \ 
    no_namespace \ 
    rename ("EOF", "adoEOF") 
    接着我在CFormView的派生类中定义 
    // 定义ADO连接、命令、记录集变量指针 
    _ConnectionPtr m_pConnection; 
    _CommandPtr m_pCommand; 
    _RecordsetPtr m_pRecordset;
    现在编译没问题,可我要是在别的函数里添哪怕是一句代码,在编译就出错了,还是这个错误
    我觉得很奇怪,我在stdafx.h文件中加了这句代码: 
    #import "c:\program files\common files\system\ado\msado15.dll" \ 
    no_namespace \ 
    rename ("EOF", "adoEOF") 
    接着我在CFormView的派生类中定义 
    // 定义ADO连接、命令、记录集变量指针 
    _ConnectionPtr m_pConnection; 
    _CommandPtr m_pCommand; 
    _RecordsetPtr m_pRecordset; 
    结果编译就出错。 
    syntax error : missing ';' before identifier 'm_pConnection' 
    e:\3\3\3view.h(42) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers 
    ...