Mein Code kompiliert, aber löst die Ausnahme aus: "Eine nicht behandelte Ausnahme vom Typ 'System, Zugriffsverletzung Ausnahme' in HealthCareProvider.exe aufgetreten Weitere Informationen: Versuch, geschützten Speicher zu lesen oder zu schreiben. HILFE??Eine nicht behandelte Ausnahme des Typs 'System, Zugriffsverletzung Ausnahme' in HealthCareProvider.exe
Problem ist mit print() -Methode. Ich weiß nicht warum. Iterator nur aus druckt ein Bündel verschiedene Zahlen (benötigt toString())
Demütig
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;
}
Haben Sie versucht, einen Debugger durchlaufen zu lassen und Zeile für Zeile durch den Code zu gehen, bis er abstürzt? Dies wird Ihnen GENAU sagen, wo es abstürzt. – Goz