Sunday, February 9, 2014

Return by reference

Newsgroup: comp.lang.c++

Subject: Return by reference

From: Giuliano Bertoletti <gbe32241@...>

Date: Sun, 09 Feb 2014 12:50:38 +0100





Hello,



I've a classes like this:



class SubObject { ... };



class Object {

public:

SubObject sub;

};



class MyClass {

public:

Object obj;



public:

SubObject &GetSubObject() { return obj.sub; } // shortcut

};



which is the difference of calling?



==================

MyClass c;



SubObject &sub = c.GetSubObject();

SubObject sub = c.GetSubObject();

==================



It compiles both ways.



In practice I've an higher number of nested classes, so GetSubObject()

is actually a shortcut which digs deep into MyClass and retrieves the

item I need.



Giulio.























via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1fWFLLL

View all the progranning help forums at:

http://ift.tt/1dP9txN

No comments:

Post a Comment