C++ – Difference Between Const Declarations

c++constantsparameterspointerssyntax

What is the difference between

void func(const Class *myClass)

and

void func(Class *const myClass)

See also:

and probably others…

Best Answer

The difference is that for

void func(const Class *myClass)

You point to a class that you cannot change because it is const. But you can modify the myClass pointer (let it point to another class; this don't have any side effects to the caller because it's pointer is copied, it only changes your local the pointer copy) In contrast

void func(Class *const myClass)

Now myClass points to a class that can be modified while you cannot change the parameter.