Given this structure:
struct Asignatura{
string nombre;
long id;
int alumT;//numero de estudiantes que ven la asignatura
int semestre;
Profesor *prof;//puntero que señala la posicion de memoria del profesor que se le asigno
};
And this function to overload the operator < <:
ostream &operator<<(ostream &o,const Asignatura &as){
return o<<" "<<as.nombre<<endl<<"DATOS:"<<endl<<"ID.: "
<<as.id<<endl<<"Semestre: "<<as.semestre<<endl<<"Profesor: "<<as.prof-
>nombre<<"\n";
}
How do I add a conditional in <<"Profesor: "<<as.prof->nombre
that says:
if(aux1->prof!=NULL){
cout<<"Profesor: "<<aux1->prof->nombre;
} else {
cout<<"\nSin profesor";
}
Because if not when a subject is shown the program closes because it is obviously trying to access a data that does not exist
* note: when I insert a new material I assure myself that prof=NULL