[英]C++ error: object of abstract class type is not allowed
Having trouble with inheritance.继承有问题。 I do not know what is wrong with the script..
我不知道脚本有什么问题..
in main在主要
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 CSVDoglist.h
class CSVDoglist : public FileAdoptionList
{
public:
void writeToFile();
void displayAdoptionlist() const;
};
FileAdoptionList.h文件收养列表.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;
};
AdoptionList.h收养清单.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() {}
};
ERRORS:错误:
object of abstract class type "CSVDoglist" is not allowed:
'CSVDoglist': cannot instantiate abstract class Adoptig Dogs
I have read more topics about this problem but I didn't found the solution.我已阅读有关此问题的更多主题,但没有找到解决方案。
Can someone help me?有人能帮我吗? Thanks
谢谢
It seems you have a typo.看来你打错了。
A function named displayAdoptionlist
(contains small l
) is declared in CSVDoglist
, but the pure virtual function displayAdoptionList
(contains large L
) isn't overrided in CSVDoglist
.在
CSVDoglist
声明了一个名为displayAdoptionlist
(包含小l
)的CSVDoglist
,但纯虚函数displayAdoptionList
(包含大L
)在CSVDoglist
没有被覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.