jeudi 12 mars 2015

Calling classes on the heap (null string error) C++


I have a project for class where I'm taking a lovely list of 50 students, placing them on the heap, and then printing them, sorting, reprinting. I have to use OOP for this, which isn't a huge deal, but I'm struggling with connecting my base data classes to their parent class. I had it where the code was compiling, but giving me a logic_error for a null string. No clue why. Started taking out any null classes, and now it's crying foul at me again. The code I'm working with is a bit huge, so I'm going to put in one of the working data classes, and then the class I'm trying to get to use the others and the main file, so bear with me here...


-data class, works as intended



.h
class Academics
{
private:
string GPA;
string credits;
public:
Academics();
Academics(string GPA, string credits);
string getAcademics();
};

.cpp begins
Academics::Academics()
{
Academics::GPA = "";
Academics::credits = "";
}
Academics::Academics(string GPA, string credits)
{
Academics::GPA = GPA;
Academics::credits = credits;
}
string Academics::getAcademics()
{
stringstream ssAcad;
ssAcad << GPA << endl << credits << endl;
return ssAcad.str();
}


-caller class, not working



.h
class Student
{
private:
Name name;
Address address;
Academics academics;
Date dob;
Date doc;
public:
Student();
Student(Name name, Address address, Date dob,
Date doc, Academics academics);
string getStudent();
};

.cpp begins
Student::Student()
{
Student::name = Name("Oscar", "Grouch");
Student::address = Address("123 Sesame Street","Trash Can","New York","NY","10128");
Student::academics = Academics("4.00", "120");
Student::doc = Date("05","21","1993");
Student::dob = Date("06","01","1969");
}
Student::Student(Name name, Address address, Date dob, Date doc, Academics academics)
{
Student::name = name;
Student::address = address;
Student::dob = dob;
Student::doc = doc;
Student::academics = academics;
}
string Student::getStudent()
{
name.getName();
address.getAddress();
dob.getDate();
doc.getDate();
academics.getAcademics();
}


-main



int main ()
{
Student student = Student();
cout << student.getStudent() << endl;
return(0);
}


thanks so much for any help or insight as to where I need to look




Aucun commentaire:

Enregistrer un commentaire