VS2010,error C2011: “Font”:“struct”类型重定义

来源:互联网 发布:dnf决战人工智能6.2 编辑:程序博客网 时间:2024/05/16 06:39

 在vs2008里添加了在VC6.0里形成的OFFICE库文件的类 excel.h,excel.cpp,就是我在VC6里做操作OFFICE的表格时候添加的库文件,然后把它们( excel.h,excel.cpp)加载vs2008里(因为vs2008里夹在的类在很多的文件夹里,而不是在一个文件夹)
然后就报很多的错误。下面的错误只是一部分,
错误 1 error C2011: “Font”: “struct”类型重定义
错误 2 error C2011: “Picture”: “struct”类型重定义
错误 3 error C2027: 使用了未定义类型“Font”
错误 4 error C3861: “InvokeHelper”: 找不到标识符
错误 5 error C2027: 使用了未定义类型“Font”
错误 6 error C3861: “InvokeHelper”: 找不到标识符
错误 7 error C2027: 使用了未定义类
错误 14 error C3861: “InvokeHelper”: 找不到标识符
错误 15 error C2027: 使用了未定义类型“Font”
错误 16 error C3861: “InvokeHelper”: 找不到标识符
错误 17 error C2027: 使用了未定义类型“Font”
错误 18 error C3861: “InvokeHelper”: 找不到标识符
错误 19 error C2027: 使用了未定义类型“Font”

 

摸索了半天,总算解决了,原因如下:在VS2008的comdef.h文件中有这么两句:struct Font : IFontDisp {};和struct Picture : IPictureDisp {};结果导致老是出现你所说的冲突,但是VC6下就没问题,原因是VC6的comdef.h文件中没有上面的这两句定义。

解决方法是为excel9添加namespace :
  将excel9.h 文件中的定义的class{}放到 namespace excel9{ } 中;

  将excel9.cpp 文件中 #ifdef...#define...的后面内容,放到 namespace excel9 {}中。

  在#include "excel9.h" 时加上 using namespace excel9;

原创粉丝点击