简体   繁体   中英

Abstract base class c++

enum InputType
{
    VideoInputType,
    ImageInputType,
    VideoStreamInputType   
};

class AbstractInput
{
public:
    AbstractInput(std::string);
    virtual InputType Type()=0;
    std::string GetName();
    virtual std::string GetFullName()=0;    
    std::string Name;

};



class VideoInput : AbstractInput
{
public:
    VideoInput(std::string,std::string);
    virtual InputType Type();
    virtual std::string GetFullName(); 

    std::vector<cv::Mat> Data;

};

class ImageInput : AbstractInput
{
public:
    ImageInput(std::string,std::string);
    virtual InputType Type();
    virtual std::string GetFullName();

    cv::Mat Data;    
};

My plan was use AbstractInput as a function parameter. Since AbstractInput is abstract class no instance could exist. But in my opinion an AbstractInput& which refers to either VideoInput or ImageInput may exist.

My code that not works:

VideoInput vidInput(ui->nameLineEdit->text().toStdString(),path.toStdString());
AbstractInput &absInput=vidInput;

Error:

'AbstractInput' is an inaccessible base of 'VideoInput'

How can I implement the behavior I want?

Thanks in advance.

You need to inherit publicly:

//"public" keyword
class VideoInput : public AbstractInput

//"public" keyword
class ImageInput : public AbstractInput

The base class is inaccessible because you are privately inheriting. Change:

class VideoInput : AbstractInput // private inheritance

to

class VideoInput : public AbstractInput // public inheritance

and same for ImageInput

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM