Accessors by value or reference?

J

Jarma

Taking such a piece of code:

template<class T>
class Data
{
public:
Data(T v) : value(v) {}

T GetValue1() const { return value; }
const T & GetValue2() const { return value; }
private:
T value;
}

GetValue1() and GetValue2() are both accessors to value. Which usage is
better? GetValue1() type seems to me to be more common although I think that
GetValue2() is more effective especially when value is a big class. Am I
right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top