class 不存在默认构造函数
No default constructor exists for a class
我在 运行 程序时遇到这些错误:
no default constructor exists for class "DynamicArray"
'DynamicArray':no appropiate default constructor available.
你能帮帮我吗?
Repository.h
class Repository {
private:
DynamicArray Repository_Dogs;
public:
Repository(int capacity , int Size_Dogs_List);
};
Dog::Dog(char* name, char* breed, char* birth_date, char* vaccinations_counter, char* photograph)
{
strcpy(this->Name, name);
strcpy(this->Breed, breed);
strcpy(this->Birth_Date, birth_date);
strcpy(this->Vaccinations_Counter, vaccinations_counter);
strcpy(this->Photograph, photograph);
}
Repository.cpp
Repository::Repository(int capacity , int size_Dogs_List)
{
DynamicArray newDynamicArray = DynamicArray(capacity,size_Dogs_List);
this->Repository_Dogs = newDynamicArray;
}
DynamicArray.cpp
DynamicArray::DynamicArray(int capacity, int size_Dogs_List)
{
this->Capacity_List = capacity;
this->Size_Dogs_List = size_Dogs_List;
this->Dogs_List = (Dog*)malloc(this->Capacity_List * sizeof(Dog));
}
DynamicArray.h(构造函数)
public:
DynamicArray(int capacity, int Size_Dogs_List);
像这样定义构造函数
Repository::Repository(int capacity , int size_Dogs_List)
: Repository_Dogs( capacity, size_Dogs_List )
{
}
并且使用 operator new 而不是 C 函数 malloc。
我在 运行 程序时遇到这些错误:
no default constructor exists for class "DynamicArray"
'DynamicArray':no appropiate default constructor available.
你能帮帮我吗?
Repository.h
class Repository {
private:
DynamicArray Repository_Dogs;
public:
Repository(int capacity , int Size_Dogs_List);
};
Dog::Dog(char* name, char* breed, char* birth_date, char* vaccinations_counter, char* photograph)
{
strcpy(this->Name, name);
strcpy(this->Breed, breed);
strcpy(this->Birth_Date, birth_date);
strcpy(this->Vaccinations_Counter, vaccinations_counter);
strcpy(this->Photograph, photograph);
}
Repository.cpp
Repository::Repository(int capacity , int size_Dogs_List)
{
DynamicArray newDynamicArray = DynamicArray(capacity,size_Dogs_List);
this->Repository_Dogs = newDynamicArray;
}
DynamicArray.cpp
DynamicArray::DynamicArray(int capacity, int size_Dogs_List)
{
this->Capacity_List = capacity;
this->Size_Dogs_List = size_Dogs_List;
this->Dogs_List = (Dog*)malloc(this->Capacity_List * sizeof(Dog));
}
DynamicArray.h(构造函数)
public:
DynamicArray(int capacity, int Size_Dogs_List);
像这样定义构造函数
Repository::Repository(int capacity , int size_Dogs_List)
: Repository_Dogs( capacity, size_Dogs_List )
{
}
并且使用 operator new 而不是 C 函数 malloc。