P
Piotre Ugrumov
I have some problems and some doubts.
I have implemented a class hierachy. The base class Velivolo, from Velivolo
derive Militare and Civile, from militare derive Aereo and Elicottero, from
Civile derive Passeggero e Merce. In every class I have implemented the
overload of << and >>. In a class Simulator (not in hierachy) I have
implemented the overload of << in this way:
ostream &operator<<(ostream &out, const Simulatore &s){
out<<"Risultato simulazione"<<endl;
for(int i=0; i<static_cast<int>(s.v.size()); i++)
out<<*(s.v)<<endl; //v is a vector of Velivoli pointer, the vector
contains object of the class Elicottero, Merce, Passeggero etc..;
return out;
}
This overload work but It's call the overload << of the class Velivolo, how
can I implement a polymorphic behaviour for <<?
Another doubt. I have implemented the class Film and the class Film. In
these 2 classes I have defined the overload of << and >>. The overloads of
<< work correctly. The overload >> of Actor works correctly too, the
overload >> of film gives me problems.
I have implemented thsi last overload in this way:
istream & operator>>(istream &in, Film &f){
string name;
int anno;
Actor a;
in>>name;
in>>year;
in>>a; //I use the overload >> of Actor
f.setTitle(name);
f.setyear(year);
f.addActor(a);
return in;
}
In the main I write this:
Film f;
cin>>f;
cout<<f;
I have the problem during execution at the moment of cout<<f; at this moment
I see stranges symbols, letters and number. The program stop the execution.
Is corettect using the overload>> of a class in the overload>> of another
class?
If I would insert a film's title with 2 or more words How can I do it?
For insert a film I write this in the prompt:
FilmTitle(one word) ProductionYear(an int) Actor(Name Surname).
Thanks to all and excuse me.
I have implemented a class hierachy. The base class Velivolo, from Velivolo
derive Militare and Civile, from militare derive Aereo and Elicottero, from
Civile derive Passeggero e Merce. In every class I have implemented the
overload of << and >>. In a class Simulator (not in hierachy) I have
implemented the overload of << in this way:
ostream &operator<<(ostream &out, const Simulatore &s){
out<<"Risultato simulazione"<<endl;
for(int i=0; i<static_cast<int>(s.v.size()); i++)
out<<*(s.v)<<endl; //v is a vector of Velivoli pointer, the vector
contains object of the class Elicottero, Merce, Passeggero etc..;
return out;
}
This overload work but It's call the overload << of the class Velivolo, how
can I implement a polymorphic behaviour for <<?
Another doubt. I have implemented the class Film and the class Film. In
these 2 classes I have defined the overload of << and >>. The overloads of
<< work correctly. The overload >> of Actor works correctly too, the
overload >> of film gives me problems.
I have implemented thsi last overload in this way:
istream & operator>>(istream &in, Film &f){
string name;
int anno;
Actor a;
in>>name;
in>>year;
in>>a; //I use the overload >> of Actor
f.setTitle(name);
f.setyear(year);
f.addActor(a);
return in;
}
In the main I write this:
Film f;
cin>>f;
cout<<f;
I have the problem during execution at the moment of cout<<f; at this moment
I see stranges symbols, letters and number. The program stop the execution.
Is corettect using the overload>> of a class in the overload>> of another
class?
If I would insert a film's title with 2 or more words How can I do it?
For insert a film I write this in the prompt:
FilmTitle(one word) ProductionYear(an int) Actor(Name Surname).
Thanks to all and excuse me.