我对这种继承概念有点新意,我无法弄清楚出了什么问题。 我很高兴能得到一些帮助。
所以我有三个班级和一个班级:
class BaseClassPipeline
{
protected:
BaseClassPipeline::BaseClassPipeline(void){};
virtual int executeFilter (SRV *p_Srv) = 0;
BaseClassPipeline::~BaseClassPipeline(void){};
};
class filter_A:public BaseClassPipeline
{
**edit: protected and not public**
**public:**
filter_A:::filter_A(void);
int filter_A::executeFilter (SRV *p_Srv){return 1}
filter_A:::~filter_A(void);
};
class PipelineAttr
{
protected:
PipelineAttr::PipelineAttr(FILE *cfgFile, SRV *p_Srv){...};
BaseClassPipeline** PipelineAttr::createPipeline(FILE *cfgFile){...};
int PipelineAttr::getNumOfFilters(){...};
PipelineAttr::~PipelineAttr(void){...};
};
class Pipeline:public BaseClassPipeline, public PipelineAttr
{
public:
Pipeline::Pipeline(FILE *cfgFile, SRV *p_Srv) : PipelineAttr(cfgFile, p_Srv){}
int Pipeline::executePipeline(SRV *p_Srv);
int Pipeline::countFilters();
Pipeline::~Pipeline(void);
};
这是主要的:
void main()
{
...
Pipeline pipe(cfgFile, srv); // trying to create instance of pipeline
}
我试图阅读其他一些帖子,但无法弄清楚我做错了什么。
我收到了这些消息:
'Pipeline':无法实例化抽象类
'filter_A :: filter_A':无法访问类'filter_A'中声明的受保护成员
感谢。
答案 0 :(得分:4)
'管道' :无法实例化抽象类
您继承自抽象基类BaseClassPipeline
。这意味着如果你不覆盖该类的纯虚函数,那么你的派生类也将是抽象的。
class Pipeline:public BaseClassPipeline, public PipelineAttr
{
public:
Pipeline::Pipeline(FILE *cfgFile, SRV *p_Srv) : PipelineAttr(cfgFile, p_Srv){}
int executeFilter (SRV *p_Srv) {} <<<< Now, you have provided the definition.
&#39; filter_A :: filter_A&#39; :无法访问类&#39; filter_A&#39;
中声明的受保护成员定义filter_A
的正确语法是: -
class filter_A:public BaseClassPipeline
{
public:
filter_A();
int executeFilter (SRV *p_Srv) { return 1; }
~filter_A();
};