Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <iostream>
- using namespace std;
- class Adresa {
- private: char* str;
- int nr;
- public:
- Adresa(){
- }
- Adresa(char* c, int n):nr(n){ //se apeleaza pseudoconstructorul pentru nr de tip int;
- //pseudoconstructorii se folosesc pentru initializarea tipurilor de date de baza
- if (c==NULL) str=NULL;
- else{
- str=new char[(strlen(c))+1];
- strcpy(str,c);
- }
- }
- Adresa(const Adresa&p){
- str=NULL;
- *this=p; //reutilizez codul scris in operator=
- }
- Adresa& operator=(const Adresa &p) {
- if(this!=&p){
- if (str!=NULL) delete [] str;
- str=new char[strlen(p.str)+1];
- strcpy(str,p.str);
- nr=p.nr;
- }
- return *this;
- }
- ~Adresa(){
- if (str!=NULL) delete[]str;
- }
- friend ostream& operator<<(ostream &dev,const Adresa &p){
- if (p.str!=NULL) dev<<"Strada: "<<p.str<<endl;
- dev<<"Nr. : "<<p.nr<<endl<<endl;
- return dev;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement