using declarations together

Jul 30, 2013 at 1:28pm
So i pretty much just finally understood the concept of using something like:
const int &var
in the parameters of a function. Where it uses the reference to quicken the process, but is not allowed to change the contents

Where this one meshes const and a reference together, are there others like this that are a shortcuts to make unique outcomes? I was looking at trying to get a list of such things.
Jul 30, 2013 at 1:32pm
The complete syntax of a C++ declaration is pretty complex. Take a look at
http://en.cppreference.com/w/cpp/language/declarations

(in your example, const int is the decl-specifier-seq, where const is the cv-qualifier and int is the simple type specifier, and &var is the declarator)
Jul 30, 2013 at 1:38pm
oh wow that is complex, thanks for the link
Jul 30, 2013 at 3:51pm
Where it uses the reference to quicken the process, but is not allowed to change the contents

More specifically - it removes the need to create a copy of the object being passed as a parameter. As well as the performance benefits, it also avoids any side-effects associated with the copy constructor - and allows you to safely pass objects that aren't copyable or haven't had a copy constructor written for them.

oh wow that is complex, thanks for the link

If it helps, I've never had to use the terms "decl-specifier-seq", "cv-qualifier" or "declarator" in nearly 20 years of being a C/C++ developer :) The way the rules work together are, mostly, logical and intuitive. "const" means pretty much the same thing with a reference as it does with anything else, for example. Once you know what "const" means, the way it applies to a reference is pretty intuitive.
Last edited on Jul 30, 2013 at 3:54pm
Topic archived. No new replies allowed.