템플릿을 사용하고 여러 추상 데이터 유형 (ADT)을 저장할 수있는 "저장소"(웨어 하우스, 원하는대로 호출)가 있습니다.특수 템플릿이있는 클래스를 호출하는 것에 관한 혼란
Rep.h
template <typename TAD>
class Repository {
public:
DynamicArray <TAD *> tad; // made a dynamic array myself, also uses templates
// since one ADT has one of the following two functions and the other doesn't
// I decided to not use TAD here
Person *findByName (string name);
Activities* findByDate(string date);
void save (TAD &p);
//etc
}
Rep.cpp
template <>
void Repository<Person>::save(Person &p) throw (RepositoryException) {
@code
}
template <>
void Repository<Activities>::save(Activities& a) throw (RepositoryException) {
@code
}
//etc
지금은 별도로 ADT의 취급 컨트롤러를, 그래서 난 단지 추상을 반영하는 저장소를 만들려면 데이터 유형 "사용자"
어떻게 호출합니까? (Person 또는 Activity를 템플릿으로 사용하는 리포지토리 형식의 개체를 만듭니다 ...)
마찬가지로 :? 링커가 전문을 만들 수 없기 때문에 (아래)
PersonController.h
Repository<Person> *repository;
ActivityController.h
Repository<Activities> *repository;
일반 템플릿 전문화를 찾고있는 것처럼 보입니까? 아니면이 작업으로 충분하지 않습니까? - BTW, 왜'std :: vector' 대신에 동적 배열을 만들었습니까? 배열에 값 대신 포인터를 저장하는 이유는 무엇입니까? 둘 다 다소 subotimal 보인다. – leftaroundabout
@leftaroundabout 숙제인데, 나는 내 자신의 동적 배열을 만들어야한다. dynamicArray는 목록 (파이썬의 목록과 같은)보다 많으며 실제 값이 아닌 클래스 요소를 저장하려는 Abstract Data (클래스)가 있으므로 값을 저장하지 않습니다. – Kalec