background preloader

Hanilozmen

Facebook Twitter

Plink by DinahMoe. Üniversite Plus - Herkes için ücretsiz online üniversite dersleri. RSS READER. Coursera. Livemocha.

Programming

Learn C++ Görsel Eğitim Seti İndirme Sitesi. Prolog. C++ Tutorial: Object Returning - 2013. Object Returning When a function, either a member function or a standalone function, returns an object, we have choices. The function could return A reference to an object A constant reference to an object An object A constant object Returning a Reference to a const object Though the main reason for using const reference is efficiency, there are restrictions on when this choice could be used. For example, suppose we want to write a function Maximum() that returns the larger of two Complx objects, where the Complx is defined as below. Output is: c1 = (10,30) c2 = (13,25) Maximum(c1,c2) = (10,30) (20,40) got its value from c3 c6 (c1+c2) = (23,55) Either of the following two implementations for Maximum() would work: There are three points that can be emphasized: Returning an object invokes the copy constructor while returning a reference doesn't.

Returning a Reference to a Non-const Object There are two common examples of returning a non-const object Complx c3 (20,40); Complx c4,c5; c5 = c4 = c3; CSS Dersleri.