Returnarea Obiectelor

  • Uploaded by: Patrick Johnston
  • 0
  • 0
  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Returnarea Obiectelor as PDF for free.

More details

  • Words: 120
  • Pages: 1
Returnarea obiectelor Cand un obiect este returnat de o functie, este creat un obiect temporar, care contine valoarea returnata. Acesta este de fapt obiectul returnat de functie. Daca obiectul care a fost returnat are un destructor care elibereaza memoria dinamica alocata, acea memorie va fi elibarata chiar daca obiectul care primeste valoarea returnata inca o mai foloseste. Exista cai de prevenire a acestei situatii care folosesc supraincarcarea operatorului de atribuire si definirea unui constructor de copii. #include using namespace std; class C { int i; public: void init(int n) { i = n; } int da() { return i; } }; C f() { C x; x.init(1); return x; } void main() { C ob; ob = f(); cout<

Related Documents


More Documents from ""