彼ら!アサーションを使用していくつかのテストを実行しようとしています。InMemoryRepository を作成したかったのですが、エラーが発生しました。これは私がやりたいことです:
void TestCaseMedicineInMemoryRepository::setUp(){
this->medRepo = new MedicineInMemoryRepository(); //error
}
エラー:
Multiple markers at this line
- The type 'MedicineInMemoryRepository' must implement the inherited pure virtual method 'MedicineInMemoryRepository::Save'
- The type 'MedicineInMemoryRepository' must implement the inherited pure virtual method 'MedicineInMemoryRepository::getAll'
- The type 'MedicineInMemoryRepository' must implement the inherited pure virtual method
'MedicineInMemoryRepository::findMedicineById'
- The type 'MedicineInMemoryRepository' must implement the inherited pure virtual method
'MedicineInMemoryRepository::deleteMedicine'
- The type 'MedicineInMemoryRepository' must implement the inherited pure virtual method
'MedicineInMemoryRepository::updateMedicine'
仮想医療リポジトリ:
class MedicineRepository{
public:
virtual void Save(Medicine* m) throw (RepositoryException) = 0;
virtual void deleteMedicine(int ID) throw (RepositoryException) = 0;
virtual void updateMedicine(Medicine* m) throw (RepositoryException) = 0;
virtual List<Medicine*> getAll()=0;
virtual Medicine* findMedicineById(int ID)=0;
};
InMemoryRepository.h:
#include "medicineRepository.h"
class MedicineInMemoryRepository : public MedicineRepository{
protected:
List<Medicine*> medList;
public:
MedicineInMemoryRepository();
virtual ~MedicineInMemoryRepository();
void Save(Medicine* m) throw (RepositoryException) = 0;
void deleteMedicine(int ID) throw (RepositoryException) = 0;
void updateMedicine(Medicine* m) throw (RepositoryException) = 0;
//int containsName(string name)=0;
List<Medicine*> getAll()=0;
//int updateQuantity(Medicine* m) throw (RepositoryException) = 0;
Medicine* findMedicineById(int ID)=0;
};
InMemoryRepository.cpp:
#include "InMemoryRepository.h"
MedicineInMemoryRepository::MedicineInMemoryRepository(){
}
MedicineInMemoryRepository::~MedicineInMemoryRepository(){
for(int i=0; i < medList.getLen(); i++){
delete medList.getElement(i);
}
}
Medicine* MedicineInMemoryRepository::findMedicineById(int ID){
for(int i=0; i < this->medList.getLen(); i++){
Medicine* m = medList.getElement(i);
if(m->getID()==ID){
return m;
}
}
return NULL;
}
List<Medicine*> MedicineInMemoryRepository::getAll(){
return medList;
}
void MedicineInMemoryRepository::Save(Medicine* m) throw (RepositoryException){
Medicine* med = findMedicineById(m->getID());
if(med != NULL){
medList.addElement(medList.getLen(), new Medicine(*m));
}
else{
throw RepositoryException("There is a medicine with the given ID!");
}
}
void MedicineInMemoryRepository::deleteMedicine(int ID) throw (RepositoryException){
int i=0;
while( i < medList.getLen() && medList.getElement(i)->getID()!=ID){
i++;
}
if(i < medList.getLen()){
Medicine* m = medList.deleteElementAtPos(i);
delete m;
}
else{
throw RepositoryException("There is no medicine with the given ID");
}
}
void MedicineInMemoryRepository::updateMedicine(Medicine* m) throw (RepositoryException){
Medicine* med = findMedicineById(m->getID());
if (med != NULL){
m->setQuantity(med->getQuantity());
m->setName(med->getName());
// this->medList->getElementAtPosition(pos).setConcentration(m.getConcentration());
deleteMedicine(med->getID());
Save(m);
}
}
上記のエラーが表示されるのは何が間違っていますか? 3時間くらい考えたけどわからない!!!