基类出现 “has incomplete type”是啥问题?

temp3000 2004-11-07 05:36:19
// base class
#ifndef BASE_H
#define BASE_H

class base
{
virtual void aaa()=0;
};
#endif

// derived class ==================================================
#ifndef DERIVE_H
#define DERIVE_H

class base;

class derive: public base
{
public:
derive();
virtual ~derive();

virtual void aaa();
};
#endif

//========================
#include "derive.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
derive::derive()
{

}

derive::~derive()
{

}

void derive::aaa()
{
}

出现:
-----------------------------------------
make -f Makefile.test_DEBUG ...
g++ -o derive.o -c -g derive.cpp
//xx/home/test/derive.cpp(7):
//xx/home/test/derive.h(13): error: base class `base' has incomplete type
make: *** [derive.o] Error 1
*********Make Finished*********

为什么?
...全文
4183 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
winux0 2004-11-10
  • 打赏
  • 举报
回复
用include也不行
winux0 2004-11-10
  • 打赏
  • 举报
回复
纯虚类的定义和实现一定要放在一个文件里,c++规定的,兄台
yanedanny 2004-11-10
  • 打赏
  • 举报
回复
你的不行是因为引入声明class base,但是没有include类描述。
yanedanny 2004-11-10
  • 打赏
  • 举报
回复
我试过,我上面说的就行呀!
yanedanny 2004-11-08
  • 打赏
  • 举报
回复
直接在derive.h文件头上加include "base.h"
去掉derive.h中的class base;
temp3000 2004-11-08
  • 打赏
  • 举报
回复
为什么啊?
temp3000 2004-11-08
  • 打赏
  • 举报
回复
把 base的定义放在 dreived.h就行了,为什么?base.h就不能单独一个文件?

#ifndef DERIVE_H
#define DERIVE_H

class base
{
public:
virtual void aaa()=0;
};

class derive: public base
{
public:
derive();
virtual ~derive();

virtual void aaa();
};
#endif
icecools 2004-11-07
  • 打赏
  • 举报
回复
去掉class base;
看看
temp3000 2004-11-07
  • 打赏
  • 举报
回复
加不加 #include base.h 都一样
icecools 2004-11-07
  • 打赏
  • 举报
回复
你#include 你的base.h了吗?

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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