What does T&& (double ampersand) mean in C++11?
Hello, colleagues! I started learning C++11 and came across a strange syntax — the double ampersand `&&` in function and template parameter declarations. For example, I saw this code:\n\n```cpp\ntemplate\nvoid foo(T&& arg) {\n // some code\n}\n```\n\nOr in the implementation of a move constructor:\n\n```cpp\nclass MyClass {\npublic:\n MyClass(MyClass&& other) noexcept;\n};\n```\n\nI understand that a single `&` is a reference (lvalue-reference). But what does the double ampersand do? Online sources say it's an "rvalue-reference," but I'm not entirely clear on how it differs from a regular reference and why it's needed. It seems to be related to move semantics and perfect forwarding, but I can't piece together the full picture.\n\nCan you explain with simple examples? Especially i
No answers yet.
Log in to leave an answer