PHP Code:
#include <iostream>
#include <string>
using namespace std;
class persona {
public:
persona (const string in_nome = "null", const string in_cognome = "null", const int in_eta =0)
:nome(in_nome), cognome(in_cognome),eta(in_eta){}
void print_nome () const {
cout << nome << endl;
}
void print_cognome () const {
cout << cognome << endl;
}
void print_eta () const {
cout << eta << endl;
}
const string & get_nome () const {
return nome;
}
const string & get_cognome () const {
return cognome;
}
int & get_eta () {
return eta;
}
void add_eta (int value){
eta+=value;
}
private:
const string nome;
const string cognome;
int eta;
};
persona operator++(persona & oggetto, int value){ // postfix
persona old(oggetto);
oggetto.add_eta(1);
return old;
}
persona & operator++(persona & oggetto){ ///////// prefix
oggetto.add_eta(1);
return oggetto;
}
ostream & operator<< (ostream & out, persona & oggetto){
out << oggetto.get_eta();
return out;
}
istream & operator>> (istream & in, persona &oggetto){
int tmp;
in >> tmp;
oggetto.add_eta(tmp);
return in;
}
int main (){
persona obj1; // create object
cout << (obj1++).get_eta() << endl; // increment but return old value - postfix
cout << (obj1).get_eta() << endl; // new value avaible now - postfix
cout << (++obj1).get_eta() << endl; // new value avaible immediately - prefix
///// testing << overloading
cout << obj1 << endl;
/// tesing >> overloading
cin >> obj1 ;
cout << obj1;
return 0;
}