does it mean, my afile will store and value and then i will use other object to access the value? sort of like pointer?
ps, can you recommend me a book that is easy to pick up c++ skill
currently im reading up c++ primer & The C++ Programming.Language.4th.Edition.Jun.2013[A4]. I find it too complex to understand.
I can't recommend you easy books because normally those bored me. I normally prefer o'reilly types of books and cut the chase and get to the core of the issue since at my level, I don't need the author to handhold me on how to go about doing each thing.
You are advice to go kinokuniya or any bookstore and read through the books few chapters and see if the author style suits you. It's not about books being easy, it's about how the author structure the topics to make it flow nicely in you.
Reference is pointer like, but in C++ it function like an alias rather than pointer.
My name is David, but maybe in another world, people call me John. That doesn't mean it's 2 different people, it's still the same me. Because in the world, there is only one ME. In actual fact, David is an alias just as John is.
When I wrote
"david" is an alias for the object created.
It seems different from
Code:
Class *david = new Class();
But actually the idea is very similar. It's analogous to hardlinks and symbolic links in the Unix filesystem.
Pointers are symbolic links, while alias/references are hardlinks.
When I do this
What I did is on top on the earlier alias called "david" which is name for an object, I created another alais called "john" also referencing the same object. Memory addresses are at play here because ultimately your computer will not see "david" or "john". The computer is only interested in the object that you are referring to which is Object X at memory address YYYYY;
Pointer is different in the language, it is a symbolic link and hence it creates a memory location to store another memory location as value.
Code:
int i = 123;
int *m = &i;
int &n = i;
Pointer "m" has a part of the memory allocated maybe at memory location XYZ to store the memory location of integer "i". "m" is an alias for the memory location at XYZ. When I when to access the value at which the pointer "m" is pointing to, I will need to dereference it like this
On the other hand, reference "n" is an alias for integer "i", hence when you want to use the reference, you just have to code
This reference concept is for C++, and it the naming convention is different from languages likes Java, where References in Java are indeed strict Pointers concept.
You see the confusion is what we called "devil in the details". You don't understand what goes under the hood, you forever need to assume based on the concept and can't fully understand why different programming languages called the same thing with different names and how they are actually implemented.