Link icon after declaring a C ++ method

In which case benificial declares a method or function using const & instead of using const? I know that using const says that this method does not change the members of the class, but what exactly happens when I add the link sign after?

Example:

int myclass::getInteger() const& {
    return theInt;
}

By the way, is this the so-called reference quartz? And more importantly, what does the reference sign say about the getInteger method? Thank!

+4
source share
1 answer

Yes, this is the function of a ref-qualified member . Designation lvalue-reference to the right makes this function is called only for lvalues myclass, ie:

myclass c;
c.getInteger(); // OK
myclass{}.getInteger(); // Compile-time error
+5
source

Source: https://habr.com/ru/post/1665769/


All Articles