Visual C++6.0技术内幕中的奇怪问题!

hearttree 2001-07-19 01:12:33
我正在看技术内幕,看到16章,遇到了一个问题,我死活都没有搞得懂是怎么回事.在这一章里的例子ex16b中,我按照书中所说,一步一步的实现这个例子,然后编译,结果却出现了这样一个错误:
\student.h(59) : error C2143: syntax error : missing ';' before '<'
还有: \studoc.h(22) : error C2143: syntax error : missing ';' before '*'
等等。我最初以为是我输错了,我就把配套光盘上的例子中的student.h,student.cpp直接复制过来然后编译,结果一样的出现这个错误,但是我编译光盘上的例子就没有出错。然后我就干脆新建一个工程,不作任何修改,然后把student.h和student.cpp直接add to project,然后编译,还是出错,如下:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
student.cpp
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
Error executing cl.exe.

test.exe - 2 error(s), 0 warning(s)

我真的是是在没辙了,有那位兄台能帮帮我,这到底是怎么回事,一定把分送上!谢谢了!
...全文
203 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
hearttree 2001-07-19
  • 打赏
  • 举报
回复
这本书其实原著相当不错,只不过翻译的确实太差,而且印刷错误也是奇多,很多东西都只有自己连猜带蒙,但是,好像全面介绍vc的书没有看见什么好书了,就只有用这一本了。
ithc 2001-07-19
  • 打赏
  • 举报
回复
我没看过但听说该书口啤不好
hearttree 2001-07-19
  • 打赏
  • 举报
回复
问题就出在我说的要在StdAfx.h中加#include <afxtempl.h>上。谢谢你们的关心。
hearttree 2001-07-19
  • 打赏
  • 举报
回复
呵呵,兄台,我得问题刚刚我已经自己解决了,谢谢你的好意了。当然,你也可以看看ftp://202.115.132.106,我得工程就在这上面。谢谢了!
aha_yang 2001-07-19
  • 打赏
  • 举报
回复
代码没问题,我按你的编译,OK!我想问题出在你的VC上,以前我也遇到过类似的问题,在别人的机器上编译通过,我这就不行,后来重装了VC,就OK了,你不妨试试。
xtra 2001-07-19
  • 打赏
  • 举报
回复
把你的出错的工程打个包发到xtra2000@elong.com.
hearttree 2001-07-19
  • 打赏
  • 举报
回复
写错了,是#include <afxtempl.h>
hearttree 2001-07-19
  • 打赏
  • 举报
回复
哈哈哈哈,我已经解决问题了,原来是我忘了使用模板需要在StdAfx.h中加一句
#include <afxtemp.h>
呵呵,我刚才仔细看了一下帮助,终于,发现了,现在问题已经解决!
谢谢各位关注了!
mikemao 2001-07-19
  • 打赏
  • 举报
回复
主要错误提示:
'CStudentList' : missing storage-class or type specifiers
mikemao 2001-07-19
  • 打赏
  • 举报
回复
大哥,你的CStudentList是在哪定义的?
hearttree 2001-07-19
  • 打赏
  • 举报
回复
真的是没有高手指点指点了?我是没办法在加分了,我只能加这么多,要不然我一定加500分的。
hearttree 2001-07-19
  • 打赏
  • 举报
回复
其实我最开始都还是以为是我可能什么地方输错了,我就没管,继续往后看,看到了18章,我实现它的例子,结果一样的错误,这才使我发现不对劲了。
sim 2001-07-19
  • 打赏
  • 举报
回复
我今天也与到了同样的问题!
可能出在模板!我的问题还没解决!
hearttree 2001-07-19
  • 打赏
  • 举报
回复
这是编译出错的说明:


--------------------Configuration: ex16b - Win32 Debug--------------------
Compiling...
ex16b.cpp
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\studoc.h(23) : error C2143: syntax error : missing ';' before '*'
h:\vc\ex16b\studoc.h(23) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(23) : error C2501: 'GetList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(25) : warning C4183: 'GetList': member function definition looks like a ctor, but name does not match enclosing class
h:\vc\ex16b\studoc.h(57) : error C2146: syntax error : missing ';' before identifier 'm_studentList'
h:\vc\ex16b\studoc.h(57) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(57) : error C2501: 'm_studentList' : missing storage-class or type specifiers
h:\vc\ex16b\stuview.h(16) : error C2143: syntax error : missing ';' before '*'
h:\vc\ex16b\stuview.h(16) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\stuview.h(16) : error C2501: 'm_pList' : missing storage-class or type specifiers
student.cpp
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
StuDoc.cpp
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\studoc.h(23) : error C2143: syntax error : missing ';' before '*'
h:\vc\ex16b\studoc.h(23) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(23) : error C2501: 'GetList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(25) : warning C4183: 'GetList': member function definition looks like a ctor, but name does not match enclosing class
h:\vc\ex16b\studoc.h(57) : error C2146: syntax error : missing ';' before identifier 'm_studentList'
h:\vc\ex16b\studoc.h(57) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(57) : error C2501: 'm_studentList' : missing storage-class or type specifiers
H:\VC\ex16b\StuDoc.cpp(84) : error C2065: 'm_studentList' : undeclared identifier
H:\VC\ex16b\StuDoc.cpp(96) : error C2228: left of '.GetHeadPosition' must have class/struct/union type
H:\VC\ex16b\StuDoc.cpp(96) : fatal error C1903: unable to recover from previous error(s); stopping compilation
StuView.cpp
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\student.h(55) : error C2143: syntax error : missing ';' before '<'
h:\vc\ex16b\studoc.h(23) : error C2143: syntax error : missing ';' before '*'
h:\vc\ex16b\studoc.h(23) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(23) : error C2501: 'GetList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(25) : warning C4183: 'GetList': member function definition looks like a ctor, but name does not match enclosing class
h:\vc\ex16b\studoc.h(57) : error C2146: syntax error : missing ';' before identifier 'm_studentList'
h:\vc\ex16b\studoc.h(57) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\studoc.h(57) : error C2501: 'm_studentList' : missing storage-class or type specifiers
h:\vc\ex16b\stuview.h(16) : error C2143: syntax error : missing ';' before '*'
h:\vc\ex16b\stuview.h(16) : error C2501: 'CStudentList' : missing storage-class or type specifiers
h:\vc\ex16b\stuview.h(16) : error C2501: 'm_pList' : missing storage-class or type specifiers
H:\VC\ex16b\StuView.cpp(79) : error C2065: 'm_pList' : undeclared identifier
H:\VC\ex16b\StuView.cpp(79) : error C2440: '=' : cannot convert from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
H:\VC\ex16b\StuView.cpp(111) : error C2227: left of '->GetHeadPosition' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(125) : error C2227: left of '->IsEmpty' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(126) : error C2227: left of '->GetHeadPosition' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(134) : error C2227: left of '->IsEmpty' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(135) : error C2227: left of '->GetTailPosition' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(145) : error C2227: left of '->GetPrev' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(157) : error C2065: 'm_postion' : undeclared identifier
H:\VC\ex16b\StuView.cpp(157) : error C2440: '=' : cannot convert from 'int' to 'struct __POSITION *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
H:\VC\ex16b\StuView.cpp(158) : error C2227: left of '->GetNext' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(161) : error C2440: '=' : cannot convert from 'struct __POSITION *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
H:\VC\ex16b\StuView.cpp(179) : error C2440: '=' : cannot convert from 'int' to 'struct __POSITION *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
H:\VC\ex16b\StuView.cpp(180) : error C2227: left of '->GetNext' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(182) : error C2227: left of '->GetHeadPosition' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(189) : error C2227: left of '->GetAt' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(190) : error C2227: left of '->RemoveAt' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(204) : error C2227: left of '->GetHeadPosition' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(214) : error C2227: left of '->GetTailPosition' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(224) : error C2039: 'OnUpdateStudentPrev' : is not a member of 'StudentView'
h:\xin\vc\ex16b\stuview.h(12) : see declaration of 'StudentView'
H:\VC\ex16b\StuView.cpp(230) : error C2039: 'OnUpdateStudentNext' : is not a member of 'StudentView'
h:\xin\vc\ex16b\stuview.h(12) : see declaration of 'StudentView'
H:\VC\ex16b\StuView.cpp(239) : error C2227: left of '->GetAt' must point to class/struct/union
H:\VC\ex16b\StuView.cpp(256) : error C2227: left of '->InsertAfter' must point to class/struct/union
Generating Code...
Error executing cl.exe.

ex16b.exe - 58 error(s), 3 warning(s)
hearttree 2001-07-19
  • 打赏
  • 举报
回复
这是我得StuDoc.cpp:

// StuDoc.cpp : implementation of the StudentDoc class
//

#include "stdafx.h"
#include "ex16b.h"

#include "StuDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// StudentDoc

IMPLEMENT_DYNCREATE(StudentDoc, CDocument)

BEGIN_MESSAGE_MAP(StudentDoc, CDocument)
//{{AFX_MSG_MAP(StudentDoc)
ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// StudentDoc construction/destruction

StudentDoc::StudentDoc()
{
TRACE("Entering CStudentDoc constructor\n");
#ifdef _DEBUG
afxDump.SetDepth(1); //Ensure dump of list elements
#endif //_DEBUG
}

StudentDoc::~StudentDoc()
{
}

BOOL StudentDoc::OnNewDocument()
{
TRACE("Entering CStudentDoc::OnNewDocument\n");

if (!CDocument::OnNewDocument())
return FALSE;

// TODO: add reinitialization code here
// (SDI documents will reuse this document)

return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// StudentDoc serialization

void StudentDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}

/////////////////////////////////////////////////////////////////////////////
// StudentDoc diagnostics

#ifdef _DEBUG
void StudentDoc::AssertValid() const
{
CDocument::AssertValid();
}

void StudentDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
dc<<"\n"<<m_studentList<<"\n";
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// StudentDoc commands

void StudentDoc::DeleteContents()
{
#ifdef _DEBUG
Dump(afxDump);
#endif
while(m_studentList.GetHeadPosition()){
delete m_studentList.RemoveHead();
}
}

void StudentDoc::OnEditClearAll()
{
DeleteContents();
UpdateAllViews(NULL);
}

void StudentDoc::OnUpdateEditClearAll(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_studentList.IsEmpty());
}
hearttree 2001-07-19
  • 打赏
  • 举报
回复
这是我得StuDoc.h:

// StuDoc.h : interface of the StudentDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_STUDOC_H__03364929_9B39_4DBB_B8DB_FE3256F9CBD8__INCLUDED_)
#define AFX_STUDOC_H__03364929_9B39_4DBB_B8DB_FE3256F9CBD8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "student.h"


class StudentDoc : public CDocument
{
protected: // create from serialization only
StudentDoc();
DECLARE_DYNCREATE(StudentDoc)

// Attributes
public:
CStudentList* GetList(){
return &m_studentList;
}

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(StudentDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual void DeleteContents();
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~StudentDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
//{{AFX_MSG(StudentDoc)
afx_msg void OnEditClearAll();
afx_msg void OnUpdateEditClearAll(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CStudentList m_studentList;
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STUDOC_H__03364929_9B39_4DBB_B8DB_FE3256F9CBD8__INCLUDED_)
codemon 2001-07-19
  • 打赏
  • 举报
回复
把错误行代码贴上来
hearttree 2001-07-19
  • 打赏
  • 举报
回复
这是我得student.h,直接复制的光盘上的,这是肯定应该没错的。因为我编译光盘上的文件就没报错。

// student.h

#ifndef _INSIDE_VISUAL_CPP_STUDENT
#define _INSIDE_VISUAL_CPP_STUDENT

class CStudent : public CObject
{
DECLARE_SERIAL(CStudent)
public:
CString m_strName;
int m_nGrade;

CStudent()
{
m_nGrade = 0;
}

CStudent(const char* szName, int nGrade) : m_strName(szName)
{
m_nGrade = nGrade;
}

CStudent(const CStudent& s) : m_strName(s.m_strName)
{
// copy constructor
m_nGrade = s.m_nGrade;
}

const CStudent& operator =(const CStudent& s)
{
m_strName = s.m_strName;
m_nGrade = s.m_nGrade;
return *this;
}

BOOL operator ==(const CStudent& s) const
{
if ((m_strName == s.m_strName) && (m_nGrade == s.m_nGrade)) {
return TRUE;
}
else {
return FALSE;
}
}

BOOL operator !=(const CStudent& s) const
{
// Let抯 make use of the operator we just defined!
return !(*this == s);
}

virtual void Serialize(CArchive& ar);

#ifdef _DEBUG
void Dump(CDumpContext& dc) const;
#endif // _DEBUG
};

typedef CTypedPtrList<CObList, CStudent*> CStudentList;

#endif // _INSIDE_VISUAL_CPP_STUDENT
red_eyes 2001-07-19
  • 打赏
  • 举报
回复
没有这个例子,所以看不明白。
runbuff 2001-07-19
  • 打赏
  • 举报
回复
我没看过《Visual C++6.0技术内幕》,我估计你在进行宏定义的时候输入有错误。
检查一下student.h第55行引用了宏没有,有的话,检查这个宏的定义。

16,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧