Mon code compile mais lance une exception: "Une exception non gérée de type 'System, Access Exception Violation' est survenue dans HealthCareProvider.exe Informations supplémentaires: Vous avez essayé de lire ou d'écrire de la mémoire protégée. AIDEZ-MOI??Une exception non gérée de type 'System, Access Violation Exception' s'est produite dans HealthCareProvider.exe
Le problème est lié à la méthode print(). Je ne sais pas pourquoi. Iterator imprime seulement un tas nombre différent (a besoin toString())
Humblement,
Mike
#ifndef _HEALTHCAREPROVIDER_H
#define _HEALTHCAREPROVIDER_H
#include <string>
#include <iostream>
using namespace std;
class HealthCareProvider{
public:
//constructor
HealthCareProvider(const string &lname, const string &fname, const string &type, const int &yearsExperience, const string &coType):
lastName(lname),firstName(fname),providerType(type),yearsExp(yearsExperience),companyType(coType)
{
}
//Last Name
void setLastName(const string &lname){
lastName = lname;
}
string getLastName()const{
return lastName;
}
... etc.
//coType
void setCompanyType(const int &coType){
companyType = coType;
}
string getCompanyType()const{
return companyType;
}
void print() const {
cout<<"Name: "<< getLastName()<<", " <<getFirstName()<<"\nType : "<<getProviderType()<<"\nYears Experience: "<<getYearsExp()<<" \nCompany Type : "<<getCompanyType()<<endl;
}
virtual double billForTreatment() = 0;
private:
int yearsExperience, yearsExp;
string type, coType, lname, fname;
string lastName, firstName, providerType, companyType;
};
#endif
#include <vector>
#include <list>
#include <iostream>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include "HealthCareProvider.h"
#include "Dentist.h"
using namespace std;
int main(){
string value;
cout << fixed << setprecision (2);
//populate
vector < HealthCareProvider*> healthCareProviders (6);
healthCareProviders [0]=new Dentist("Thatcher","Donald","Dentist",10, "sole proprietorship");
healthCareProviders [1]=new Dentist("Parker","Michelle","Dentist",5, "LLC");
healthCareProviders [2]= new Dentist("Bradford","Michael","Dentist",12, "LLC");
healthCareProviders [3] = new Dentist("Craig","Elizabeth","Dentist",4, "sole proprietorship");
for (size_t i=0; i<healthCareProviders.size(); i++){
healthCareProviders[i] ->print();
cout<<endl;
}
for (size_t j =0; j< healthCareProviders.size(); j++){
delete healthCareProviders [j];
}
cout<<"Pause . . ."<<endl;
cin>>value;
}
Avez-vous essayé d'exécuter un débogage et de parcourir le code ligne par ligne jusqu'à ce qu'il se bloque? Cela vous dira exactement où il se bloque. – Goz