`
444878909
  • 浏览: 631562 次
文章分类
社区版块
存档分类
最新评论

c++中的纯虚函数和提示"cannot instantiate abstract class due to following members"

 
阅读更多

首先看一下下面的代码

class CTaskBase  
{  
    private:  
 /*1.需子类实现的纯虚函数*/  
 virtual bool OnTaskStart() = 0;  
 virtual void OnTaskStop() = 0;  
 virtual void OnDealReportTask(CVorxProto* pTask) = 0;  
 virtual void OnDealQueryTask(CVorxProto* pTask) = 0;  
 virtual void OnDealHeartReturn(CVorxProto* pTask) = 0;  
 virtual void OnDealHeartQuery(CVorxProto* pTask) = 0;  
}  

这个类中包含了纯虚函数,包含了纯虚函数的类,不能被实例化,比如 CTaskBase tb =newCTaskBase();,是不行的。

当派生出一个类:


class CMatrixAgent: public CTaskBase  
{  
 	virtual bool OnTaskStart() = 0;  
 	virtual void OnTaskStop() = 0;  
 	virtual void OnDealReportTask(CVorxProto* pTask) = 0;  
 	virtual void OnDealQueryTask(CVorxProto* pTask) = 0;  
 	virtual void OnDealHeartReturn(CVorxProto* pTask) = 0;  
 	virtual void OnDealHeartQuery(CVorxProto* pTask) = 0;  
} 

这些函数必须在.cpp里实现:

bool CMatrixAgent::OnTaskStart()  
{  
 m_thread.StartThread();  
 return true;  
}  
  
void CMatrixAgent::OnTaskStop()  
{  
   
}  
  
void CMatrixAgent::OnDealReportTask(CVorxProto* pTask)  
{  
   
}  
void CMatrixAgent::OnDealQueryTask(CVorxProto* pTask)  
{  
  
}  
void CMatrixAgent::OnDealHeartReturn(CVorxProto* pTask)  
{  
  
}  
void CMatrixAgent::OnDealHeartQuery(CVorxProto* pTask)  
{  
  
}  

如果不这样,就会有"cannot instantiate abstract class due to following members"的提示。


转载请注明原创链接:http://blog.csdn.net/wujunokay/article/details/12295287






分享到:
评论

相关推荐

    myclipse+jboss+ejbStateless

    <br> 测试代码完成测试 <br> 报错:Cannot instantiate class: org.jnp.interfaces.NamingContextFactory <br> 添加 引用 <br>继续报错是因为JNDI访问名称错误,也是用了原来的那个了。哈哈。...

    C++简单练习.cpp

    (SavingsAccount Class) Create a SavingsAccount class. Use a static data member annualInterestRate to store the annual interest rate for each of the savers. Each member of the class contains a private ...

    log4cplus 源码(C++编写的开源的日志系统)

    log4cplus是C++编写的开源的日志系统,功能非常全面,用到自己开发的工程中会比较专业的,:),本文介绍了log4cplus基本概念,以及如何安装,配置。 ### 简介 ### log4cplus是C++编写的开源的日志系统,前身是java...

    mybatis.generator ecliapse 插件

    解压后,把里面的featurs 和plugins 复制到eclipse安装目录下 ,重启eclipse

    Unity3D入门 :Prefabs(预设)与 Instantiate(实例化)

    学习使用Prefabs和instantiate使用方法!

    burpsuite_v1.01

    On startup, burp searches its classpath for a class called BurpExtender, and attempts to dynamically load and instantiate this class. The IBurpExtender methods implemented will then be dynamically ...

    Unity3D教程:Prefabs与Instantiate1

    Unity3D教程:Prefabs与Instantiate1

    Unity中Instantiate实例化物体卡顿问题的解决

    本文实例为大家分享了Unity中Instantiate实例化物体卡顿问题的解决方法,供大家参考,具体内容如下 一、前言 当在执行多次Instantiate实例化物体时,会卡顿严重甚至在移动端会导致程序崩溃 因为Instantiate会产生...

    yii2-deep-instantiate

    该软件包提供了Yii 2依赖注入器容器,该容器能够自动解决嵌套的构造函数接口类型的依赖项。 要求 Yii 2.0.39.3+ PHP 7.0以上 安装 composer require bizley/deep-instantiate:^1.0 用法 直接-只需调用new \Bizley\...

    解决Hive启动失败Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

    FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient 通过控制台的...

    mybatis generator mysql

    mybatis generator相关资源 包含配置文件,jar包等 补充

    MyBatis-Generator 自动生成Lombok标签 不生成Get/Set方法

    把下载的jar包放在 Maven仓库的 org\mybatis\generator\mybatis-generator-core\1.3.5 下面即可,然后在generatorConfig配置文件中加上 </plugin> 即可

    BroadcasReceivert的两种注册模式

    1)第一种不是常驻型广播,也就是说广播跟随注册他的Activity的生命周期。 2)第二种是常驻型,也就是说当应用程序关闭后,如果有信息广播来,程序也会被系统调用自动运行。

    Android代码-smash

    Smash is Volley inspired ...To request content of server as String do following: String url = "https://github.com/appformation/smash"; SmashStringRequest request = new SmashStringRequest(SmashRequest.Me

    @AspectJ配置Spring AOP,demo

    @AspectJ配置Spring AOP,文档,Aspect jar包, 可运行的demo,

    Unity.5.From.Zero.to.Proficiency.B01EJCE85M

    Chapter 3 gets you to use C# to instantiate, use and control Rigidbody objects from your script as well as explosions. Chapter 4 explains how to create a simple weapon management system. You will ...

    org.hibernate.HibernateException: No Hibernate Session bound to thread

    No Hibernate Session bound to thread,没有绑定线程解决办法,找了好久才找到的

    单例模式与工厂模式.docx

    定义:Define an interface for creating an object,but let subclasses decide which class to instantiate.Factory Method lets a class defer instantiation to subclasses. (定义一个用于创建对象的接口,让...

    loca_table.rar_Table

    Constructor scope altered to public for base class to instantiate.

    java实验6(Person.java)

    Write a class called Person with the following attributes: title (Mr., Mrs., Ms., etc.) first name last name nickname age in years sex (boolean - true/false to indicated either male or ...

Global site tag (gtag.js) - Google Analytics