Method return types

Please explain the difference between following methods. I need to know what they actually returns and their use. Both complied and ran same way,

1
2
3
4
5
6
7
8
9
10
11
12
13
class ClassA;

class MyClass
{
public:
	MyClass(void);
	virtual ~MyClass(void);
	ClassA &GetClassA2(){return o_A;} //method 1
	ClassA GetClassA3(){return o_A;} //method 2

private:
	ClassA o_A;
};


Thanks
Last edited on
The one on line 8 returns a reference, which you can then modify and o_A will change with it. The second one returns o_A's value, which if you modify won't have an impact on o_A.

Does this answer your question?

-Albatross
Yes, thank you.
Topic archived. No new replies allowed.