我有一个msword.h msword.cpp excel.h excel.cpp   在MFC下 msword.h  excel.h中 有同名函数!!!!
我采用了空间命名克服,编译是可以的。但是在CCUCDlg.h  中引用 msword.h  excel.h  就会报一个错 
D:\学习\operateword\software\work\Excel\CUC\CUC.cpp(17) : error C2888: 'const struct AFX_MSGMAP *__thiscall CCUCApp::GetMessageMap(void) const' : symbol cannot be defined within namespace 'f_excel'
D:\学习\operateword\software\work\Excel\CUC\CUC.cpp(17) : error C2888: 'const struct AFX_MSGMAP CCUCApp::messageMap' : symbol cannot be defined within namespace 'f_excel'
D:\学习\operateword\software\work\Excel\CUC\CUC.cpp(17) : error C2888: 'const struct AFX_MSGMAP_ENTRY CCUCApp::_messageEntries[]' : symbol cannot be defined within namespace 'f_excel'
D:\学习\operateword\software\work\Excel\CUC\CUC.cpp(29) : error C2888: '__thiscall CCUCApp::CCUCApp(void)' : symbol cannot be defined within namespace 'f_excel'那个f_excel是在excel.h中的命名的如下:#include<iostream>
using namespace std;namespace f_excel
{
class CalloutFormat : public COleDispatchDriver
{
public:
。}
//接下来进入excel.cpp#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "stdafx.h"
#include "excel9.h"....一些函数实现}//整个命名空会括号在这里结束!!!错误指向
BEGIN_MESSAGE_MAP(CCUCApp, CWinApp)
//{{AFX_MSG_MAP(CCUCApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP() 

解决方案 »

  1.   

    你的CCUCApp类声明中有DECLARE_MESSAGE_MAP()这句吗?
      

  2.   


    ???肯定没有啊
    我自己建立一个MFC对话框工程
    就添加了我所说的4个文件,再在头文件应用引用了excel.h就出错了
      

  3.   

    大神能否留个QQ,我把工程传给你~~你看看怎么调试~~我想在VC6.0下做,我笔记本带不动VS2010
      

  4.   

    或者 能否给出一个正确的,方便的命名空间方法,我引用WORD,excel的库,里面有很多重名函数,怎么克服?
      

  5.   

    一个名空间里的东西只能在本名空间或者父命空间里声明或者定义。否则就会C2888namespace A
    {
    class C
    {
    static int x;
    };
    }namespace B
    {
    int A::C::x; // 你犯的错误是这个,你在f_excel名空间里定义了别的名空间的东西
    }另外:
    1. 用命空间必须保证全名一致。你把函数f()在.h里的声明变成A::f(),.cpp里的定义也要变成A::f()。
    2. 小心VC6.0和VS.net的MFC相当的不一样。
      

  6.   

    如果用MFC的话,我建议你不要把类放在namespace里面。你最好还是把名称冲突的类改名为好。