Is there ANY EVER reason why i would return an object or variable by reference? to me this doesn't make sense and is very bad.
maybnxtseasn
0
Newbie Poster
Recommended Answers
Jump to Postyou'll end up with hell of a debugging time.
:) contaz you got the job, you walk in a part where demons and monsters are willingly
ready to kill you.
Jump to PostYes there is, e.g. in the 'singleton' pattern. Or when you have a global static class that holds objects that should be modifiable.
Usually though, you are right that you don't want to do this. But returning a const& is very common, for example in getter functions.
All 6 Replies
NicAx64
76
Posting Pro
thelamb
163
Posting Pro in Training
mrnutty
761
Senior Poster
NicAx64
76
Posting Pro
mrnutty
761
Senior Poster
Narue
5,707
Bad Cop
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.