Suggested improvement to C++ Language Tutorial

I have not used C++ for many years and I am following your tutorial to refresh and update my knowledge.
The Pointers section explains * and & prefixes, but does not explain the & postfix. Fair enough, it will be introduced later.
In the Classes (II) section dealing with operator overloading the & postfix does appear, but with no explanation as to what it is.
Eventually in the Copy Constructor part of the next section it is described as a 'reference to the class itself', which still needs clarification.
As far as I am able to remember, I would define it as used on an argument that is passed as a pointer but used as if it has already been dereferenced. I think this should be explained at the start of the Classes (II) section. (especially if I have got it wrong!)
Hello mfarmiloe,

As I have read in other posts the tutorial here does need to be updated, but for the most part it helps sometimes.

You may find this https://www.learncpp.com/ to be more updated with information and examples that are easierr to understand.

Andy
OK thanks, I'll check that out too, but I have found your tutorial to go at a good pace.
> the & postfix
┬┐what's that?
The Pointers section explains * and & prefixes, but does not explain the & postfix

Two operators used with pointers as prefix and postfix are ++ and --. Used to increment and decrement through an array using pointer math.

https://www.learncpp.com/cpp-tutorial/6-8a-pointer-arithmetic-and-array-indexing/

The address-of (&) and dereference (*) operators are not prefix/postfix related.

https://www.learncpp.com/cpp-tutorial/67-introduction-to-pointers/

Suggesting changes to the content of CPlusPlus needs to be made to the site's admin (the "Spotted an error? contact us" link at the bottom of every page).
Last edited on
'reference to the class itself'

-- a reference is LIKE a pointer in many ways, but is not a pointer.
if you look at a tutorial on c++ references, it will help.

as far as your question...

class foo
{
foo (const foo &input); // header for copy constructor has a reference (not a pointer) to the same type as the class for its parameter (because you are planning on copying from a thing of type foo to another thing of type foo).

}

these work just like a reference parameter in any other function.
void bar(int &x); //x was passed by reference and if x is changed inside the function it will change what was passed into it. If this is not familiar, you need to stop here and study this carefully.
Last edited on
a reference is LIKE a pointer in many ways, but is not a pointer.


To forestall a bunfight that happens over and over... :)

While it is true that many implementations often choose to implement references "under the hood" as memory addresses (i.e. identical to a pointer), that's "just" an implementation detail. In the C++ language, a reference is not the same as a pointer, and a reference is not "just a dereferenced pointer".

As Jonnin says, a reference is not a pointer, even if compilers often choose to write the assembly code related to a reference similarly to how they write assembly related to pointers.
Last edited on
Topic archived. No new replies allowed.