初手问个弱问题——支持MFC的Win32控制台应用程序中类的定义和使用?
1.首先是类的定义:
在test.h中,类的声明如下:
class CitationDataBase{
public:
CitationDataBase(CString CitationDbLocation){
CitationDb.Open(CitationDbLocation);
//其他代码略
}
~CitationDataBase(){
//其他代码略
CitationDb.Close();
getchar();
}
void CreateTrie();
}
2.然后在test.cpp里中定义CreateTrie方法的实现:
#include "CitationDataBase.h"
void CitationDataBase::CreateTrie(){
//代码略
}
3.然后在应用程序中使用这个类:
#include "stdafx.h"
#include "afxdao.h"
#include "test.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 唯一的应用程序对象
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("致命错误:MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
CitationDatabase DbTest("相似字符串匹配技术"); //出错????
DbTest.CreateTrie();
}
return nRetCode;
}
编译后出现的主要错误是:
error C2512:“CitationDataBase” : 没有合适的默认构造函数可用
error C2065: “CitationDatabase” : 未声明的标识符
error C2501: “theApp” : 缺少存储类或类型说明符
真不清楚到底哪个地方出错了?熟手指点,谢谢