P
Piotre Ugrumov
I'm following your help. I have written the overload of the operator <<.
This overload work!
But I have some problem with the overload of the operator >>. I have written
the overload of this least operator for the class Person, but I don't know
how write the overload for a class that derived from the class Person.
The overload of << in Person is this:
ostream & operator<<(ostream &out, const Persona &p){
out<<p.getNome()<<" "<<p.getCognome()<<", "<<p.getDataNascita()<<endl;
return out;
}
The overload of << in class Client: Public Person:
ostream & operator<<(ostream &out, const Cliente &p){
out<<"Cliente: "<<endl;
out<<(Persona)p;
out<<"Credito: "<<p.getCredito()<<endl;
return out;
}
The overload of >> in class Person is:
istream & operator>>(istream &in, Persona &p){
char tmp1[30];
char tmp2[30];
char tmp3[30];
in>>tmp1;
in>>tmp2;
in>>tmp3;
p.setName(tmp1);
p.setSurname(tmp2);
p.setDateOfBirth(tmp3);
return in;
}
but how can I implement the overload of >> in the class Client?
?????
Another thing about the overload of>>.
If I create a new class and in this class I insert object of the class
Client and of the class Tradar(derives from Person) how can implemente the
overload of >>?
The overload of << is ok, but the overload of >>? How can I implement this
overload?
In a class I have defined:
Client *cPtr;
Film *fPtr;
Actor *aPtr;
int csize, fsize, asize;
I inizilize all these element to 0.
For add an object I have created this function:
void Archiveo::addClient(Client &c){
Client *tmp=cPtr;
csize = csize+1;
cPtr=new Cliente[csize];
for(int i=0; i<csize; i++)
cPtr=tmp;
cPtr[csize-1]=c;
delete[] tmp;
}
The compiler don't give me any error, but when I execute a main with an
instruction like this: a.addClient(a); all is blocked.
How can resolve this problem?
Thanks.
This overload work!
But I have some problem with the overload of the operator >>. I have written
the overload of this least operator for the class Person, but I don't know
how write the overload for a class that derived from the class Person.
The overload of << in Person is this:
ostream & operator<<(ostream &out, const Persona &p){
out<<p.getNome()<<" "<<p.getCognome()<<", "<<p.getDataNascita()<<endl;
return out;
}
The overload of << in class Client: Public Person:
ostream & operator<<(ostream &out, const Cliente &p){
out<<"Cliente: "<<endl;
out<<(Persona)p;
out<<"Credito: "<<p.getCredito()<<endl;
return out;
}
The overload of >> in class Person is:
istream & operator>>(istream &in, Persona &p){
char tmp1[30];
char tmp2[30];
char tmp3[30];
in>>tmp1;
in>>tmp2;
in>>tmp3;
p.setName(tmp1);
p.setSurname(tmp2);
p.setDateOfBirth(tmp3);
return in;
}
but how can I implement the overload of >> in the class Client?
?????
Another thing about the overload of>>.
If I create a new class and in this class I insert object of the class
Client and of the class Tradar(derives from Person) how can implemente the
overload of >>?
The overload of << is ok, but the overload of >>? How can I implement this
overload?
In a class I have defined:
Client *cPtr;
Film *fPtr;
Actor *aPtr;
int csize, fsize, asize;
I inizilize all these element to 0.
For add an object I have created this function:
void Archiveo::addClient(Client &c){
Client *tmp=cPtr;
csize = csize+1;
cPtr=new Cliente[csize];
for(int i=0; i<csize; i++)
cPtr=tmp;
cPtr[csize-1]=c;
delete[] tmp;
}
The compiler don't give me any error, but when I execute a main with an
instruction like this: a.addClient(a); all is blocked.
How can resolve this problem?
Thanks.