I looked up the convention you suggested LowestOne before and decided to use it. Thanks. As result I haven't really looked at this thread in a week or so.
Thanks for everyone's help but I would like to clear something up if possible:
Things have not changed with regards to the code you illustrated with, and your claim is as false pre-standard as it is with the current standard. |
Hmm... well if that is not the case (if my statement is false regarding the past) I wish someone could explain to me why any object returned from that function was always inaccessible or more often... contained garbage data. Whenever I debugged a program that used that convention when I started programming, the data would not be data I assigned to the variable within the function. Presumably because stuff on the stack had already overwritten that memory space. So I started using pointers allocated with new keyword instead. This caused a lot of frustration when I was first starting with C++. I know this may be difficult without actual examples from when I had the problems but it was a good while ago and I changed the code anyway.
Also, why do older games who have released their source code (Such as Civ4) always using pointers or reference types instead of strait objects? I would accept saving time as a reason were it not from my own experiences.
FYI my programming background: I started with C in 1995 and C++ back in 1997 for small things. Around 2003-2004 I started using C# and and used it for quite a bit of time in most of my projects because it was "easier" and quicker to get things done. In 2006-2007 I went back to C++ for a project I developed with a team (a mod for Civ4:Warlords using their publicly released SDK).
Recently I have been using C++ again because I am working on a new, very large, project that makes use of Qt (for its cross-platform GUI) and because based on my experience with programs developed with different languages, C++ is faster at the kind of thing I am currently working on.
One big question about "references" has arisen from my working with C#. C# hides the difference between references, pointers, and objects because it treats what it calls "references" similarly to pointers (actually garbage collected pointers) and all object variables are actually of this type. (You can assign null to a reference in C#). (In the case of unsafe code, an actual pointer can be used but the object must explicitly be kept from being moved by the memory manager). In moving back to C++ it is clear that there is a gap in my understanding in what it calls a reference. C++ treats references more similarly to objects themselves. So what is the difference between what is returned from the following functions?
1 2
|
MyClass& getObjectReference();
MyClass getObject();
|
Perhaps I should put this question in another thread?