我有一个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()
我采用了空间命名克服,编译是可以的。但是在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()
???肯定没有啊
我自己建立一个MFC对话框工程
就添加了我所说的4个文件,再在头文件应用引用了excel.h就出错了
{
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相当的不一样。