user1673206
user1673206

Reputation: 1711

inheritance errors- cannot instantiate abstract class\ cannot access protected member declared in class

I am kind of new with this inheritance concept and I cant figure it out what's wrong. I will be happy for some help please.

so I have three classes and one main:

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);
};

this is the main:

void main()
{
 ...
 Pipeline pipe(cfgFile, srv); // trying to create instance of pipeline
}

I tried to read some other posts but couldn't figure it out what am I doing wrong.

I get those messages:

'Pipeline' : cannot instantiate abstract class

'filter_A::filter_A' : cannot access protected member declared in class 'filter_A'

thanks.

Upvotes: 2

Views: 88

Answers (1)

ravi
ravi

Reputation: 10733

'Pipeline' : cannot instantiate abstract class

You are inheriting from abstract base class BaseClassPipeline. That means if you don't override pure virtual functions of that class, then your derived class would also be abstract.

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.

'filter_A::filter_A' : cannot access protected member declared in class 'filter_A'

Correct syntax for defining filter_A would be:-

class filter_A:public BaseClassPipeline
{
 public:
   filter_A();
   int executeFilter (SRV *p_Srv) { return 1; }
   ~filter_A();
};

Upvotes: 4

Related Questions