C++错误:不允许使用抽象类类型的对象
C++ error: object of abstract class type is not allowed
继承有问题。我不知道剧本出了什么问题。。
在主中
int main(){
Repository repo("dogs.txt");
FileAdoptionList* a = new CSVDoglist{}; / here is the error
Controller ctrl(repo, dogValidator{}, a);
UI ui(ctrl);
ui.startUI();
delete a;
}
CSVDoglist.h
class CSVDoglist : public FileAdoptionList
{
public:
void writeToFile();
void displayAdoptionlist() const;
};
文件采用列表.h
class FileAdoptionList : public AdoptionList
{
protected:
std::string filename;
public:
FileAdoptionList();
virtual ~FileAdoptionList() {}
void setFilename(const std::string& filename);
virtual void writeToFile() = 0;
virtual void displayAdoptionList() const = 0;
};
采用列表.h
class AdoptionList
{
protected:
std::vector<Dog> storage;
public:
AdoptionList();
// Adds a dog to the playlist.
void add(const Dog& dog);
// Checks if the adoptionlist is empty.
bool isEmpty();
virtual ~AdoptionList() {}
};
错误:
object of abstract class type "CSVDoglist" is not allowed:
'CSVDoglist': cannot instantiate abstract class Adoptig Dogs
我已经阅读了更多关于这个问题的主题,但我没有找到解决方案。
有人能帮我吗?感谢
您似乎有拼写错误。
在CSVDoglist
中声明了名为displayAdoptionlist
(包含小l
)的函数,但在CSVDoglist
中没有覆盖纯虚拟函数displayAdoptionList
(包含大L
)。
相关文章:
- E0322:不允许使用抽象类类型 " " 的对象
- 分配抽象类类型 c++ xcode 的对象
- 分配抽象类类型为"CObject"的对象
- 错误消息:不允许抽象类类型 "X" 的对象:纯虚拟"Y"没有覆盖器
- 错误:不允许使用抽象类类型的对象
- 我在代码中有一个错误,错误是:(智能感知:不允许抽象类类型"HourlyWorker"的对象:)
- OOP - 抽象类类型,初始化基类和派生类中的变量
- 创建一个抽象类类型的集合,shared_ptr的抽象类向量
- 意外地'instantiate'使用大括号初始值设定项的抽象类类型?
- C++错误:不允许使用抽象类类型的对象
- 使用 std::vector 时抽象类类型"Shape"的新表达式无效错误
- 提升::可选抽象类类型
- 不允许抽象类类型的对象 "Vector<LinkedList<int>>"
- 在我的代码中分配抽象类类型的对象
- 使用抽象类类型的 c++ 传递对象会给出错误:不是 GeneralDriverInterface 的成员
- 分配抽象类类型的对象
- 在尝试创建SceneNode时分配抽象类类型的对象
- 分配抽象类类型为"形状"的对象?
- 不允许抽象类类型 "DiamondMap" 的对象
- 抽象类类型.是不允许的,纯虚函数是不重写的