O.K., I have a project I'm working on. It uses 8 classes (I'm only showing 2 and main). It gives me a "bad_alloc" error when the obj is instantiated. When obj is removed it works fine (or call the personType class that "should" be inherited from extPersonType.) Any thoughts of what I am missing or doing wrong?
(class header - TO BE inherited)
using namespace std;
#ifndef PERSONTYPE_H
#define PERSONTYPE_H
class personType{
protected:
string firstName;
string lastName;
public:
void print()const;
void setName(string first, string last);
string getFirstName()const;
string getLastName()const;
personType(string first = "", string last = "");
/*personType();*/
};
#endif
( same class defined )
#include <string>
#include <iostream>
#include "personType.h"
using namespace std;
void personType::print()const{
cout << endl;
cout << firstName << " " << lastName << endl;
}
void personType::setName(string first, string last){
firstName = first;
lastName = last;
}
string personType::getFirstName()const{
return firstName;
}
string personType::getLastName()const{
return lastName;
}
personType::personType(string first,string last){
firstName = first;
lastName = last;
}
//personType::personType(){
//
// firstName = "";
// lastName = "";
//}
( class header to inherit personType)
using namespace std;
class extPersonType:public personType{
private:
string relation;
string phone;
public:
void print()const;
void setRelation(string phone, string extRelation);
void setPhone(string extPhone);
void setRelation(string extRelation);
string getRelation()const;
string getPhone()const;
extPersonType(string relation = "",string phone = "");
/*extPersonType();*/
};
(same class defined )
#include <string>
#include <iostream>
#include "personType.h"
#include "extPersonType.h"
//#include "dateType.h"
//#include "addressType.h"
using namespace std;
void extPersonType::print()const{
cout << relation << " " << phone << endl;
}
void extPersonType::setRelation(string extRelation){
relation = extRelation;
}
void extPersonType::setPhone(string extPhone){
phone = extPhone;
}
string extPersonType::getRelation()const{
return relation;
}
string extPersonType::getPhone()const{
return phone;
}
extPersonType::extPersonType(string extRelation, string extPhone)
:personType(firstName,lastName) {
relation = extRelation;
phone = extPhone;
}
////extPersonType::extPersonType():personType()/*:dateType():addressType()*/{ //maybe the same here :personType(...):addressType(...)
////
//// relation = "";
//// phone = "";
////}
(main() that calls extPersonType obj to pass values to make the personType class do it's inherited work. - bad_alloc error on compile )
#include <fstream>
#include <iostream>
#include <string>
#include "personType.h"
#include "addressType.h"
#include "extPersonType.h"
#include "dateType.h"
using namespace std;
int main(){
//ofstream file;
//file.open("MyTxT.txt");
cout << "****************** Welcome to your address book. ***********************\n" << endl;
string first,last;
extPersonType myExt;
//personType myPerson; --> for another class
cout << "Enter the first name: ";
getline(cin,myExt.firstName);
cout << "Enter the last name: ";
getline(cin,myExt.lastName);
myExt.setName(first,last);
//cin.sync();
//cin.peek();
//
};
any information, thoughts, help, ideas are greatly appreciated