我从CObject派生了一个新类CShape然后又从CShape派生了一个CLine我在CShape里用了
DECLARE_SERIAL(CShape) 和 IMPLEMENT_SERIAL(CShape,CObject,1)
编译正确;但是我在CLine里
DECLARE_SERIAL(CLine)
IMPLEMENT_SERIAL(CLine,CShape,1)
却编译出现了问题,好像runtime class 里得那些函数都找不到了,这样用有错误吗?高手告诉我,该怎么实现阿???
DECLARE_SERIAL(CShape) 和 IMPLEMENT_SERIAL(CShape,CObject,1)
编译正确;但是我在CLine里
DECLARE_SERIAL(CLine)
IMPLEMENT_SERIAL(CLine,CShape,1)
却编译出现了问题,好像runtime class 里得那些函数都找不到了,这样用有错误吗?高手告诉我,该怎么实现阿???
class CDrawDataTag:public CObject
{
public:
CPoint point;//used for the line
int radius;//used for the arch
BOOL m_bFlag;//true for drawing line ,false for drawing arch!
CDrawDataTag(CPoint pt,int rd);
public:
virtual void Serialize(CArchive &ar);protected:
//support serliaizing
CDrawDataTag( );
DECLARE_SERIAL(CDrawDataTag)
};//the beginning of implementation of class CDrawDataTagIMPLEMENT_SERIAL(CDrawDataTag,CObject,1)CDrawDataTag::CDrawDataTag()//used by CreateObject();
{
//only used by serializing!
}
CDrawDataTag::CDrawDataTag(CPoint pt ,int rd):point(pt),radius(rd)
{
this->m_bFlag=true;
}
void CDrawDataTag::Serialize(CArchive &ar)
{
//important!!!
//序列化的功能很是强大!!
//宋业文 2002年10月5日
if(ar.IsStoring())
{
ar<<(WORD)point.x<<(WORD)point.y<<(WORD)radius<<(WORD)m_bFlag;
}
else
{
WORD x,y,rd,fg;
ar>>x;
ar>>y;
ar>>rd;
ar>>fg;
point.x=x;
point.y=y;
radius=rd;
m_bFlag=fg;
}}
那个IMPLEMENT_SERIAL宏一展开就出现这么多的错误,天啊
为什么用CObject直接做基类就可以????
Line.cpp
e:\my software\geometry\line.h(18) : error C2143: syntax error : missing ';' before 'public'
E:\MY SOFTWARE\Geometry\Line.cpp(19) : error C2509: 'CreateObject' : member function not declared in 'CLine'
e:\my software\geometry\line.h(14) : see declaration of 'CLine'
E:\MY SOFTWARE\Geometry\Line.cpp(19) : error C2509: '_GetBaseClass' : member function not declared in 'CLine'
e:\my software\geometry\line.h(14) : see declaration of 'CLine'
E:\MY SOFTWARE\Geometry\Line.cpp(19) : error C2039: 'classCLine' : is not a member of 'CLine'
e:\my software\geometry\line.h(14) : see declaration of 'CLine'
E:\MY SOFTWARE\Geometry\Line.cpp(19) : error C2248: '_GetBaseClass' : cannot access protected member declared in class 'CShape'
e:\my software\geometry\shape.h(23) : see declaration of '_GetBaseClass'
E:\MY SOFTWARE\Geometry\Line.cpp(19) : error C2509: 'GetRuntimeClass' : member function not declared in 'CLine'
e:\my software\geometry\line.h(14) : see declaration of 'CLine'
E:\MY SOFTWARE\Geometry\Line.cpp(19) : error C2039: 'classCLine' : is not a member of 'CLine'
e:\my software\geometry\line.h(14) : see declaration of 'CLine'
E:\MY SOFTWARE\Geometry\Line.cpp(19) : error C2039: 'classCLine' : is not a member of 'CLine'
e:\my software\geometry\line.h(14) : see declaration of 'CLine'
Error executing cl.exe.Line.obj - 8 error(s), 0 warning(s)
----侯sir说CLine::CLine()
{
}
{
DECLARE_SERIAL(CLine)
}IMPLEMENT_SERIAL(CLine,CObject,0)
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_SHAPE_H__3907A100_31D9_4096_ADAA_BF06480738A6__INCLUDED_)
#define AFX_SHAPE_H__3907A100_31D9_4096_ADAA_BF06480738A6__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000class CShape : public CObject
{
public:
virtual void Serialize(CArchive &ar);
CShape();
virtual ~CShape();
DECLARE_SERIAL(CShape)////////////////////////////////
public:
virtual BOOL Draw(CDC *pDC);};#endif // !defined(AFX_SHAPE_H__3907A100_31D9_4096_ADAA_BF06480738A6__INCLUDED_)// Line.h: interface for the CLine class.
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_LINE_H__CD0074B9_D4CF_4D58_BF6E_1252CA47EFFF__INCLUDED_)
#define AFX_LINE_H__CD0074B9_D4CF_4D58_BF6E_1252CA47EFFF__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include "Shape.h"class CLine : public CShape
{
protected:
DECALRE_SERIAL(CLine)
public:
CLine();
virtual ~CLine();
virtual void Serialize(CArchive &ar);};#endif // !defined(AFX_LINE_H__CD0074B9_D4CF_4D58_BF6E_1252CA47EFFF__INCLUDED_)各位大哥,头文件就这个样子,我还没有开始往里边添函数和变量就这个样子了
搞死掉了
原来是我把DECLARE写成了DECALRE我真的错了,跟贴的都给分吧,谢谢