P
Piotre Ugrumov
I have tried to implement the overload of these 2 operators.
ostream & operator<<(ostream &out, Person &p){
out<<p.getName()<<" "<<p.getSurname()<<", "<<p.getDateOfBirth()<<endl;
return out;
}
This overload work but I have a curiosty
If I try to approch to the name or to the surname or to the dateofbirth in
this way i receive error:
ostream & operator<<(ostream &out, Person &p){
out<<p.name<<" "<<p.surname<<", "<<p.dateofbirth<<endl;
return out;
}
I don't know how implement the overload of >>, I have tried in this way but
this system don't work:
istream & operator>>(istream &in, Person &p){
char tmp1[30];
char tmp2[30];
char tmp3[30];
in>>tmp1;
in>>tmp2;
in>>tmp3;
Person::setName(tmp1);
Persona::setSurname(tmp2);
Persona::setDateOfBirth(tmp3);
return in;
}
How can I implement the overload o the operator >>?
I have defined these overload in this class:
#pragma once
#include <iostream>
using namespace std;
class Person
{
friend ostream & operator<<(ostream &, const Persona &);
friend istream & operator>>(istream &, Persona &);
public:
Persona(char *n, char *c, char *dn);
void setName(char *n);
void setSurname(char *c);
void setDataOBirth(char *dn);
char* getName();
char* getSurname();
char* getDateOfBirth();
~Persona(void);
protected:
char *name, *surname, *dateofbirth;
};
If in a class son of Person I define the overload of << and >>, can I do
this thing?
ostream & operator<<(ostream &out, Person &p){
Person:perator<<
//do something
return out;
}
istream & operator>>(istream &in, Person &p){
Person:perator>>
//do something
return in;
}
Thanks.
ostream & operator<<(ostream &out, Person &p){
out<<p.getName()<<" "<<p.getSurname()<<", "<<p.getDateOfBirth()<<endl;
return out;
}
This overload work but I have a curiosty
If I try to approch to the name or to the surname or to the dateofbirth in
this way i receive error:
ostream & operator<<(ostream &out, Person &p){
out<<p.name<<" "<<p.surname<<", "<<p.dateofbirth<<endl;
return out;
}
I don't know how implement the overload of >>, I have tried in this way but
this system don't work:
istream & operator>>(istream &in, Person &p){
char tmp1[30];
char tmp2[30];
char tmp3[30];
in>>tmp1;
in>>tmp2;
in>>tmp3;
Person::setName(tmp1);
Persona::setSurname(tmp2);
Persona::setDateOfBirth(tmp3);
return in;
}
How can I implement the overload o the operator >>?
I have defined these overload in this class:
#pragma once
#include <iostream>
using namespace std;
class Person
{
friend ostream & operator<<(ostream &, const Persona &);
friend istream & operator>>(istream &, Persona &);
public:
Persona(char *n, char *c, char *dn);
void setName(char *n);
void setSurname(char *c);
void setDataOBirth(char *dn);
char* getName();
char* getSurname();
char* getDateOfBirth();
~Persona(void);
protected:
char *name, *surname, *dateofbirth;
};
If in a class son of Person I define the overload of << and >>, can I do
this thing?
ostream & operator<<(ostream &out, Person &p){
Person:perator<<
//do something
return out;
}
istream & operator>>(istream &in, Person &p){
Person:perator>>
//do something
return in;
}
Thanks.