主题:组建c++出问题了,求救!!!
wwwwwww116
[专家分:0] 发布于 2009-03-05 09:56:00
我的代码编译没问题,但在组建的时候出现错误了,请高手指点一下:
[size=1][color=FF0000]error C2065: 'CUserRecordSet' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'm_UserRecordSet'
error C2065: 'm_UserRecordSet' : undeclared identifier
error C2228: left of '.IsOpen' must have class/struct/union type[/color][/size]
这两个错误怎么改正呢,请指教小弟不胜感激!!
最后更新于:2009-03-05 09:58:00
回复列表 (共6个回复)
沙发
星绽紫辉 [专家分:1700] 发布于 2009-03-05 10:26:00
看看CUserRecordSet的头文件有没有包含进来。。。
板凳
wwwwwww116 [专家分:0] 发布于 2009-03-05 11:08:00
我给你看看源程序吧(红色的是组建出错误的地方):// Demo02View.cpp : implementation of the CDemo02View class
//
#include "stdafx.h"
#include "Demo02.h"
#include "Demo02Doc.h"
#include "Demo02View.h"
//增加CMainFrame的引用声明
#include"MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDemo02View
IMPLEMENT_DYNCREATE(CDemo02View, CListView)
BEGIN_MESSAGE_MAP(CDemo02View, CListView)
//{{AFX_MSG_MAP(CDemo02View)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemo02View construction/destruction
CDemo02View::CDemo02View()
{
// TODO: add construction code here
}
CDemo02View::~CDemo02View()
{
}
BOOL CDemo02View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
//注释:设置CListCtrl的格式为:LVS_REPORT 并且 LVS_SINGLESEL
cs.style|=LVS_REPORT|LVS_SINGLESEL;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDemo02View drawing
void CDemo02View::OnDraw(CDC* pDC)
{
CDemo02Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CDemo02View::OnInitialUpdate()
{
//创建一个CListCtrl指针,
CListCtrl *ctl;
//将CListCtrl指针指向CListView和CListCtrl
ctl=&GetListCtrl();
//利用CListCtrl的指针,设置列的题头
ctl->InsertColumn(0,"用户ID",LVCFMT_LEFT,50);
ctl->InsertColumn(1,"用户名",LVCFMT_LEFT,60);
ctl->InsertColumn(2,"密码",LVCFMT_LEFT,60);
ctl->InsertColumn(3,"权限",LVCFMT_LEFT,60);
ctl->InsertColumn(4,"性别",LVCFMT_LEFT,60);
ctl->InsertColumn(5,"住址",LVCFMT_LEFT,60);
ctl->InsertColumn(6,"单位",LVCFMT_LEFT,60);
ctl->InsertColumn(7,"电子邮箱",LVCFMT_LEFT,60);
ctl->InsertColumn(8,"职务",LVCFMT_LEFT,60);
ctl->InsertColumn(9,"电话",LVCFMT_LEFT,60);
ctl->InsertColumn(10,"个人介绍",LVCFMT_LEFT,100);
CListView::OnInitialUpdate();
//获取CMainFrame指针
CMainFrame *m_Frm=(CMainFrame *)::AfxGetMainWnd();
//将CMainFrame的m_ListView指针变量指向CDemo02View的实例
m_Frm->m_ListView=this;
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CDemo02View printing
BOOL CDemo02View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDemo02View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDemo02View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDemo02View diagnostics
#ifdef _DEBUG
void CDemo02View::AssertValid() const
{
CListView::AssertValid();
}
void CDemo02View::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CDemo02Doc* CDemo02View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemo02Doc)));
return (CDemo02Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDemo02View message handlers
void CDemo02View::RemoveAll()
{ //增加值针变量指向ListView的CListCtrl
CListCtrl *ctl;
ctl=&GetListCtrl();
//删除CListCtrl中的所有记录;
ctl->DeleteAllItems();
}
void CDemo02View::ListUser(CString strUserName)
{
//删除前此输出德尔用户记录
RemoveAll();
//建立一个指针,用以操作ListCtrl输出用户记录
CListCtrl *ctl;
ctl=&GetListCtrl();
//创建CUserRecordSet的实例
[color=FF0000] CUserRecordSet m_UserRecordSet;[/color]
//记录用户序号
int i=0;
//定义一个变量来保存“%”以便设置SQL语句
char chrTemp='%';
CString strTemp;
try
[color=FF0000]{ if(m_UserRecordSet.IsOpen())
m_UserRecordSet.Close();[/color]
//设置查询条件"UserName=strUserName"
[color=FF0000]m_UserRecordSet.m_strFilter.Format("UserName like'%c%s%c'order by UserID ASC", [/color] chrTemp,strUserName.operator LPCTSTR(),chrTemp);
m_UserRecordSet.Open(CRecordset::snapshot,NULL,CRecordset::none);
//输出匹配上查询条件用户记录,直到记录为空
while(!m_UserRecordSet.IsBOF())
{ //将userID从整型转换为CString,以便输出
strTemp.Format("%d",m_UserRecordSet.m_UserID);
//设置ListCtrl记录的Itim值
ctl->InsertItem(i,steTemp);
ctl->SetItemText(i,1,m_UserRecordSet.m_UserName);
ctl->SetItemText(i,2,m_UserRecordSet.m_UserPwd);
ctl->SetItemText(i,3,m_UserRecordSet.m_UserAble);
ctl->SetItemText(i,4,m_UserRecordSet.m_UserSex);
ctl->SetItemText(i,5,m_UserRecordSet.m_UserDep);
ctl->SetItemText(i,6,m_UserRecordSet.m_UserAddr);
ctl->SetItemText(i,7,m_UserRecordSet.m_UserTitle);
ctl->SetItemText(i,8,m_UserRecordSet.m_UserEmail);
ctl->SetItemText(i,9,m_UserRecordSet.m_UserPhone);
ctl->SetItemText(i,10,m_UserRecordSet.m_UserInfo);
//记录游标移到下一条记录
m_UserRecordSet.MoveNext();
}//关闭记录集
if(m_UserRecordSet.IsOpen())
m_UserRecordSet.Close();
}//意外捕获
catch(CDBExcepion*e)
{ //e->ReportError();
e->Delete();
return;
}
}
3 楼
wwwwwww116 [专家分:0] 发布于 2009-03-05 11:09:00
我的源程序有点多,上面只是一部分,大家参考参考吧
4 楼
ChRise [专家分:50] 发布于 2009-03-06 22:38:00
1楼说的对,在文件开头部分加上#include "UserRecordSet.h"
5 楼
wwwwwww116 [专家分:0] 发布于 2009-03-07 11:37:00
我加进去错误更多了?怎么回事呢?
e:\实验2\userrecordset.h(14) : error C2504: 'CRecordset' : base class undefined
e:\实验2\userrecordset.h(16) : error C2629: unexpected 'class CUserRecordSet ('
e:\实验2\userrecordset.h(16) : error C2238: unexpected token(s) preceding ';'
e:\实验2\userrecordset.h(21) : warning C4518: 'long ' : storage-class or type specifier(s) unexpected here; ignored
e:\实验2\userrecordset.h(21) : error C2146: syntax error : missing ';' before identifier 'm_column1'
e:\实验2\userrecordset.h(21) : error C2501: 'm_column1' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(22) : error C2146: syntax error : missing ';' before identifier 'm_column2'
e:\实验2\userrecordset.h(22) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(22) : error C2501: 'm_column2' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(23) : error C2146: syntax error : missing ';' before identifier 'm_column3'
e:\实验2\userrecordset.h(23) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(23) : error C2501: 'm_column3' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(24) : error C2146: syntax error : missing ';' before identifier 'm_column4'
e:\实验2\userrecordset.h(24) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(24) : error C2501: 'm_column4' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(25) : error C2146: syntax error : missing ';' before identifier 'm_column5'
e:\实验2\userrecordset.h(25) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(25) : error C2501: 'm_column5' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(26) : error C2146: syntax error : missing ';' before identifier 'm_column6'
e:\实验2\userrecordset.h(26) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(26) : error C2501: 'm_column6' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(27) : error C2146: syntax error : missing ';' before identifier 'm_column7'
e:\实验2\userrecordset.h(27) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(27) : error C2501: 'm_column7' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(28) : error C2146: syntax error : missing ';' before identifier 'm_column8'
e:\实验2\userrecordset.h(28) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(28) : error C2501: 'm_column8' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(29) : error C2146: syntax error : missing ';' before identifier 'm_column9'
e:\实验2\userrecordset.h(29) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(29) : error C2501: 'm_column9' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(30) : error C2146: syntax error : missing ';' before identifier 'm_column10'
e:\实验2\userrecordset.h(30) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(30) : error C2501: 'm_column10' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(31) : error C2146: syntax error : missing ';' before identifier 'm_column11'
e:\实验2\userrecordset.h(31) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(31) : error C2501: 'm_column11' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(39) : error C2146: syntax error : missing ';' before identifier 'GetDefaultConnect'
e:\实验2\userrecordset.h(39) : error C2433: 'CString' : 'virtual' not permitted on data declarations
e:\实验2\userrecordset.h(39) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(40) : error C2146: syntax error : missing ';' before identifier 'GetDefaultSQL'
e:\实验2\userrecordset.h(40) : error C2433: 'CString' : 'virtual' not permitted on data declarations
e:\实验2\userrecordset.h(40) : error C2501: 'CString' : missing storage-class or type specifiers
e:\实验2\userrecordset.h(41) : error C2061: syntax error : identifier 'CFieldExchange'
e:\实验2\userrecordset.h(47) : error C2061: syntax error : identifier 'CDumpContext'
6 楼
星绽紫辉 [专家分:1700] 发布于 2009-03-07 18:30:00
如果你不懂这些英语的话,可以查查金山词霸,如果你看懂了,我想你应该会明白它的意思。。。
我来回复