My codeがコンパイルされましたが、例外がスローされます: "HealthCareProvider.exeで 'System、Access Violation Exception'型の未処理例外が発生しました。保護されたメモリを読み書きしようとしました... "助けて??HealthCareProvider.exeで 'System、Access Violation Exception'型の未処理の例外が発生しました
問題はprint()メソッドで発生します。どうしてか分かりません。 イテレータだけ束異なる番号を出力
何卒、
マイク
#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;
}
デバッグを実行して、コードが1行ずつ進んで、クラッシュするまで試しましたか?これはクラッシュする箇所を正確に示します。 – Goz